# Ping (/sdks/ruby/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, container liveness/readiness probes, and connection-health dashboards that need a fast, cheap go/no-go signal.

`client.ping` issues a minimal gRPC call to the server and returns a `ServerInfo` object (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.

**Gotchas:** a failed `ping` doesn't close the client — the SDK's reconnect logic keeps retrying in the background, so rescue `KubeMQ::ConnectionError` 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.

## Prerequisites [#prerequisites]

* KubeMQ server running on `localhost:50000`
* Ruby SDK installed (`gem install kubemq`)

## Code [#code]

```ruby title="main.rb"
require 'kubemq'

address = ENV.fetch('KUBEMQ_ADDRESS', 'localhost:50000')

begin
  client = KubeMQ::PubSubClient.new(address: address, client_id: 'ping-example')
  info = client.ping
  puts "Connected to #{info.host}"
  puts "Server version: #{info.version}"
  puts "Uptime: #{info.server_up_time_seconds}s"
rescue KubeMQ::ConnectionError => e
  puts "Cannot reach server: #{e.message}"
rescue KubeMQ::Error => e
  puts "KubeMQ error: #{e.message}"
ensure
  client&.close
  puts 'Done'
end
```

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

* `ping` makes a lightweight gRPC call that verifies the connection and returns `ServerInfo`.
* Use `ping` for health checks, readiness probes, or startup verification.
* Review timeouts, channel names, and client IDs before running against shared environments.

## Related [#related]

* [Ruby SDK Reference](/sdks/ruby/reference)
* [Connect](/sdks/ruby/tutorials/connect)
* [Connection Error](/sdks/ruby/how-to/error-handling/connection-error)
