# Ping (/sdks/go/how-to/connection/ping)



## Overview [#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, Kubernetes liveness/readiness probes, and connection-health dashboards that need a fast, cheap go/no-go signal.

`client.Ping(ctx)` issues a minimal gRPC health-check RPC to the server and returns a `*ServerInfo` (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 check the returned error 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 `NewClient` can still surface setup errors.

## Prerequisites [#prerequisites]

* KubeMQ server running on `localhost:50000`
* Go SDK installed (`go get github.com/kubemq-io/kubemq-go/v2`)

## Code [#code]

```go title="main.go"
// Example: connection/ping
//
// Demonstrates how to ping a KubeMQ server to verify connectivity and
// retrieve server information (host, version, uptime).
//
// Channel: go-connection.ping
// Client ID: go-connection-ping-client
//
// Run with a KubeMQ server on localhost:50000
// (see https://docs.kubemq.io/deploy).
package main

import (
	"context"
	"fmt"
	"log"
	"time"

	"github.com/kubemq-io/kubemq-go/v2"
)

func main() {
	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
	defer cancel()

	client, err := kubemq.NewClient(ctx,
		kubemq.WithAddress("localhost", 50000),
		kubemq.WithClientId("go-connection-ping-client"),
	)
	if err != nil {
		log.Fatal(err)
	}
	defer client.Close()

	// Ping the server to verify connectivity and retrieve server info.
	info, err := client.Ping(ctx)
	if err != nil {
		log.Fatalf("Ping failed: %v", err)
	}
	fmt.Printf("Ping OK: host=%s version=%s uptime=%ds\n",
		info.Host, info.Version, info.ServerUpTimeSeconds)
}

```

## How It Works [#how-it-works]

1. `client.Ping(ctx)` sends a lightweight gRPC health-check RPC to the broker and returns `*ServerInfo` on success.
2. `info.Host` is the broker's advertised hostname, `info.Version` is its build version string, and `info.ServerUpTimeSeconds` is how long the server has been running — useful for dashboards and startup readiness checks.
3. A `Ping` error does not close the client; the gRPC reconnect policy continues to attempt reconnection. Use `Ping` in readiness probes that need to surface temporary unavailability.
4. The 10-second context deadline bounds both the `NewClient` dial and the `Ping` call.

## Related [#related]

* [Go SDK Reference](/sdks/go/reference)
* [Connect](/sdks/go/tutorials/connect)
* [Close](/sdks/go/how-to/connection/close)
