Ping
Send a health-check ping to verify KubeMQ server connectivity and read server info using the C# SDK.
Overview
A ping is a lightweight liveness check — you call it to confirm the broker is actually reachable before sending real traffic, without standing up a publisher, subscriber, or queue client just to find out. It's the tool of choice for startup readiness checks, container liveness/readiness probes, and connection-health dashboards that need a fast, cheap go/no-go signal.
await client.PingAsync() issues a minimal Ping gRPC call to the server and returns a ServerInfo struct (Host, Version, uptime) confirming the broker answered. It works over the same connection regardless of which message types you use elsewhere on that client — events, queues, or RPC — and doesn't require a channel name.
Gotchas: a failed PingAsync() doesn't close the client — the SDK's reconnect logic keeps retrying in the background, so check the returned result or catch the exception yourself rather than assume the client tears itself down. A successful ping only confirms the broker process answered, not that a specific channel or queue exists or has capacity. And since the gRPC channel is often established lazily, call it after ConnectAsync() but before relying on real message delivery.
Prerequisites
- KubeMQ server running on
localhost:50000 - C# SDK installed (
dotnet add package KubeMQ.SDK.CSharp)
Code
// KubeMQ .NET SDK — Connection: Ping
//
// This example demonstrates pinging the KubeMQ server to verify connectivity
// and retrieve server information such as host, version, and uptime.
//
// Prerequisites:
// - KubeMQ server running on localhost:50000
// - dotnet run
using KubeMQ.Sdk.Client;
var options = new KubeMQClientOptions
{
Address = "localhost:50000",
ClientId = "csharp-connection-ping-client",
};
await using var client = new KubeMQClient(options);
await client.ConnectAsync();
Console.WriteLine("Pinging KubeMQ server...");
var info = await client.PingAsync();
Console.WriteLine($"Host: {info.Host}");
Console.WriteLine($"Version: {info.Version}");
Console.WriteLine($"Server info: {info}");
Console.WriteLine("Done.");
How It Works
await client.PingAsync()issues aPinggRPC call to the server and returns aServerInfostruct with host, version, and uptime.info.Hostreports the address the broker is listening on;info.Versionis the KubeMQ server build version.- Ping is safe to call on any connected client regardless of which message types (events, queues, RPC) are in use — it does not require a channel name.
- Use ping in liveness probes or startup checks to confirm the broker is reachable before sending messages.
Related
- Getting started
- C# SDK Reference
- Connect
- Close
Was this page helpful?