KubeMQ
Client SDKsPythonHow-to guidesConnection

Ping

Ping the KubeMQ server with the Python SDK to verify connectivity and check server health.

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.ping() issues a minimal gRPC health-check request to the server and returns a ServerInfo dataclass (host, version, uptime) confirming the broker answered. It works over the same connection regardless of which messaging pattern you use elsewhere on that client — events, queues, commands, or queries — and doesn't touch any channel.

Gotchas: a failed ping() doesn't close the client — the SDK's reconnect logic keeps retrying in the background, so catch the raised 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, the first call you make is what actually triggers the connection, so a ping right after opening the client can still surface setup errors.

Prerequisites

  • KubeMQ server running on localhost:50000
  • Python SDK installed (pip install kubemq)

Code

ping.py
"""Example: Ping — check server health and retrieve server information."""

from __future__ import annotations

import asyncio

from kubemq import AsyncQueuesClient


async def main() -> None:
    async with AsyncQueuesClient(
        address="localhost:50000",
        client_id="python-connection-ping-client",
    ) as client:
        server_info = await client.ping()
        print(f"Server host: {server_info.host}")
        print(f"Server version: {server_info.version}")
        print(f"Server uptime: {server_info.server_up_time_seconds}s")
        print(f"Server is reachable: True")


if __name__ == "__main__":
    asyncio.run(main())

How It Works

client.ping() sends a gRPC health-check request and returns a ServerInfo dataclass. The fields printed here — host, version, and server_up_time_seconds — are all available on that object. The async with block ensures close() is called even if ping raises, so no connection is leaked.

Was this page helpful?

On this page