KubeMQ
Client SDKsC++Reference

Client

Client construction, configuration, and lifecycle -- KubeMQ C++ SDK reference.

The C++ SDK exposes a single Client class backed by one gRPC connection. Use the static Client::Create() factory method with ClientOptions to configure address, TLS, auth, retries, and observability. The client is thread-safe and non-copyable (PIMPL pattern).

Include

#include "kubemq/kubemq.h"

Requires C++17. Compatible with KubeMQ server v2.2+.

Constructor

Client::Create

[[nodiscard]] static StatusOr<std::unique_ptr<Client>> Create(const ClientOptions& options);

Creates a connected client. By default, verifies connectivity with a Ping before returning (controlled by set_check_connection()).

Parameters:

NameTypeRequiredDescription
optionsconst ClientOptions&YesConnection and behavior configuration

Returns: StatusOr<std::unique_ptr<Client>> -- a connected client on success. Check ok() before accessing.

Errors: Validation, timeout, auth, or transient network errors.

Note: The client is thread-safe. Share one instance across threads rather than creating a client per request.

Lifecycle

Close

[[nodiscard]] Status Close();

Drains in-flight work (up to drain_timeout) and closes the gRPC connection. After Close, methods return kErrClientClosed.

Returns: Status -- OK on success, or transport close errors.

Ping

[[nodiscard]] StatusOr<ServerInfo> Ping();

Health check against the broker. Returns server metadata when reachable.

Returns: StatusOr<ServerInfo> -- server identity, version, and uptime fields.

State

ConnectionState State() const;

Returns the current connection state (kConnecting, kReady, kReconnecting, kClosed, etc.).

ClientOptions

MethodDefaultDescription
set_address(host, port)localhost:50000Broker host and gRPC port
set_client_id(id)Auto-generatedStable client identifier
set_auth_token(token)NoneJWT or API key
set_credential_provider(p)NoneDynamic token refresh
set_tls_config(config)NoneTLS/mTLS settings
set_connection_timeout(d)10sInitial connection deadline
set_reconnect_policy(p)Infinite retriesReconnect backoff and max attempts
set_retry_policy(p)DefaultUnary RPC retry policy
set_drain_timeout(d)5sDrain timeout on Close
set_keepalive_time(d)10sgRPC keepalive ping interval
set_keepalive_timeout(d)20sgRPC keepalive timeout
set_max_receive_message_size(n)4 MBMax inbound message size
set_max_send_message_size(n)100 MBMax outbound message size
set_wait_for_ready(b)trueWait for gRPC channel ready
set_check_connection(b)truePing on connect
set_logger(l)NoneCustom logger

State Callbacks

MethodDescription
set_on_connected(cb)Connection established
set_on_disconnected(cb)Connection lost
set_on_reconnecting(cb)Reconnection attempt starting
set_on_reconnected(cb)Reconnection succeeded
set_on_closed(cb)Client permanently closed
set_on_buffer_drain(cb)Reconnect buffer overflow

Quick Usage

connect.cc
kubemq::ClientOptions opts;
opts.set_address("localhost", 50000);
opts.set_client_id("my-client");

auto client_or = kubemq::Client::Create(opts);
if (!client_or.ok()) {
    std::cerr << "Failed: " << client_or.status().ToString() << "\n";
    return 1;
}
auto& client = *client_or;

auto ping_or = client->Ping();
if (ping_or.ok()) {
    std::cout << "Connected to " << ping_or->host << "\n";
}

client->Close();

See Also

Was this page helpful?

On this page