KubeMQ
Client SDKsRustReference

Client

KubemqClient, ClientConfigBuilder, and connection types

KubemqClient

The primary entry point for all messaging operations. Thread-safe — cloning is cheap (Arc-based).

main.rs
use kubemq::prelude::*;

let client = KubemqClient::builder()
    .host("localhost")
    .port(50000)
    .client_id("my-service")
    .build()
    .await?;

Methods

MethodReturnsDescription
builder()ClientConfigBuilderCreates a new configuration builder
ping()Result<ServerInfo>Health-check that returns server metadata
close()Result<()>Graceful shutdown; cancels subscriptions and releases the gRPC channel
state()ConnectionStateReturns current connection state (synchronous)
config()&ClientConfigReturns a reference to the client configuration

ClientConfigBuilder

Builder for creating a KubemqClient. Configuration precedence: builder method > environment variable > compiled default.

Builder Methods

MethodDefaultDescription
.host(h)"localhost"Broker hostname. Falls back to KUBEMQ_ADDRESS env var
.port(p)50000Broker port number
.client_id(id)UUID v4Client identifier sent with every request
.auth_token(token)NoneAuthentication token for gRPC metadata
.tls_config(config)NoneTLS/mTLS configuration via TlsConfig
.connection_timeout(d)10sTimeout for establishing the initial connection
.check_connection(bool)falsePing the broker during build() to verify connectivity
.drain_timeout(d)5sTime allowed for in-flight tasks during close()
.keepalive_time(d)10sHTTP/2 keepalive interval (must be >= 5s)
.keepalive_timeout(d)5sHTTP/2 keepalive ping timeout
.max_receive_message_size(n)4 MBMaximum inbound message size in bytes
.max_send_message_size(n)100 MBMaximum outbound message size in bytes
.retry_policy(policy)3 retries, 100ms–10sRetryPolicy for automatic reconnection
.rpc_timeout(d)60sTimeout for RPC operations (Commands/Queries)
.on_connected(cb)NoneAsync callback on connection establishment
.on_closed(cb)NoneAsync callback on connection close
.credential_provider(p)NoneDynamic credential provider for per-request tokens

ConnectionState

main.rs
match client.state() {
    ConnectionState::Idle => println!("Not yet connected"),
    ConnectionState::Ready => println!("Connected"),
    ConnectionState::Closed => println!("Closed"),
}

TlsConfig

Configuration for TLS and mutual TLS (mTLS) connections.

FieldTypeDescription
ca_cert_fileOption<String>Path to CA certificate file
ca_cert_pemOption<Vec<u8>>PEM-encoded CA certificate bytes
cert_fileOption<String>Path to client certificate file (mTLS)
key_fileOption<String>Path to client private key file (mTLS)
cert_pemOption<Vec<u8>>PEM-encoded client certificate (mTLS)
key_pemOption<Vec<u8>>PEM-encoded client private key (mTLS)
server_nameOption<String>Override server name for TLS verification

RetryPolicy

Retry policy with exponential backoff and configurable jitter.

FieldDefaultDescription
max_retries3Maximum retry attempts (0 = unlimited)
initial_backoff100msBackoff duration for the first retry
max_backoff10sUpper bound for backoff duration
multiplier2.0Exponential multiplier per attempt
jitter_modeFullNone, Full, or Equal jitter
main.rs
use kubemq::RetryPolicy;
use std::time::Duration;

let policy = RetryPolicy {
    max_retries: 5,
    initial_backoff: Duration::from_millis(200),
    max_backoff: Duration::from_secs(30),
    multiplier: 2.0,
    ..Default::default()
};

ServerInfo

Returned by client.ping().

FieldTypeDescription
hostStringServer hostname
versionStringServer version
server_start_timei64Server start time (Unix timestamp)
server_up_time_secondsi64Server uptime in seconds

Was this page helpful?

On this page