KubeMQ
Client SDKsElixirReference

Client

KubeMQ.Client GenServer API reference — connection, lifecycle, and all messaging operations for the Elixir SDK.

KubeMQ.Client is an OTP GenServer that manages the gRPC connection and exposes all messaging operations. Start it with start_link/1 or add it to your supervision tree.

Package

mix.exs
{:kubemq, "~> 1.0"}

Requires Elixir 1.15+.

Starting the Client

{:ok, client} = KubeMQ.Client.start_link(
  address: "localhost:50000",
  client_id: "my-app"
)

address is optional — omit it to use the default:

{:ok, client} = KubeMQ.Client.start_link(client_id: "my-app")

Constructor Options

OptionTypeRequiredDescription
addressString.t()NoKubeMQ server endpoint (host:port) — defaults to "localhost:50000"
client_idString.t()YesUnique client identifier
auth_tokenString.t()NoAuthentication bearer token
tlskeyword()NoSSL options: cacertfile, certfile, keyfile, verify
rpc_timeoutpos_integer()NoDefault RPC timeout in ms (default 10_000)
reconnect_policykeyword()Noinitial_delay, max_delay, max_attempts, multiplier
default_cache_ttlpos_integer()NoDefault cache TTL for queries in ms
nameatom()NoRegister the GenServer under a name

Connection Lifecycle

FunctionSpecDescription
start_link/1(keyword()) :: {:ok, pid()} | {:error, term()}Start and connect the client
connected?/1(client) :: boolean()Check if client is connected
connection_state/1(client) :: atom()Current connection state
ping/1(client) :: {:ok, ServerInfo.t()} | {:error, Error.t()}Ping the server
close/1(client) :: :okClose connection and stop the GenServer

Events

FunctionSpecDescription
send_event/2(client, Event.t()) :: :ok | {:error, Error.t()}Send a fire-and-forget event
send_event_stream/1(client) :: {:ok, EventStreamHandle.t()} | {:error, Error.t()}Open a persistent event stream
subscribe_to_events/3(client, channel, opts) :: {:ok, Subscription.t()} | {:error, Error.t()}Subscribe to events on a channel

Subscribe Options

OptionTypeDescription
on_event(EventReceive.t() -> any())Callback for received events
on_error(Error.t() -> any())Callback for subscription errors
groupString.t()Consumer group name

Events Store

FunctionSpecDescription
send_event_store/2(client, EventStore.t()) :: {:ok, EventStoreResult.t()} | {:error, Error.t()}Send a persistent event
send_event_store_stream/1(client) :: {:ok, EventStoreStreamHandle.t()} | {:error, Error.t()}Open a persistent event store stream
subscribe_to_events_store/3(client, channel, opts) :: {:ok, Subscription.t()} | {:error, Error.t()}Subscribe with replay options

Events Store Subscribe Options

OptionTypeDescription
start_atatom or tuple:start_new_only, :start_from_first, :start_from_last, {:start_at_sequence, n}, {:start_at_time, unix}, {:start_at_time_delta, ms}
groupString.t()Consumer group name
on_event(EventStoreReceive.t() -> any())Callback for received events

Commands

FunctionSpecDescription
send_command/2(client, Command.t()) :: {:ok, CommandResponse.t()} | {:error, Error.t()}Send a command and wait for response
subscribe_to_commands/3(client, channel, opts) :: {:ok, Subscription.t()} | {:error, Error.t()}Subscribe to handle commands

Command Subscribe Options

OptionTypeDescription
on_command(CommandReceive.t() -> CommandReply.t())Handler that returns a reply
on_error(Error.t() -> any())Error callback
groupString.t()Consumer group name

Queries

FunctionSpecDescription
send_query/2(client, Query.t()) :: {:ok, QueryResponse.t()} | {:error, Error.t()}Send a query and wait for response
subscribe_to_queries/3(client, channel, opts) :: {:ok, Subscription.t()} | {:error, Error.t()}Subscribe to handle queries

Query Subscribe Options

OptionTypeDescription
on_query(QueryReceive.t() -> QueryReply.t())Handler that returns a reply
on_error(Error.t() -> any())Error callback
groupString.t()Consumer group name

Queues

FunctionSpecDescription
send_queue_message/2(client, QueueMessage.t()) :: {:ok, QueueSendResult.t()} | {:error, Error.t()}Send a single queue message
send_queue_messages/2(client, [QueueMessage.t()]) :: {:ok, QueueBatchResult.t()} | {:error, Error.t()}Send a batch of messages
receive_queue_messages/3(client, channel, opts) :: {:ok, QueueReceiveResult.t()} | {:error, Error.t()}Receive messages from a queue
ack_all_queue_messages/3(client, channel, opts) :: {:ok, QueueAckAllResult.t()} | {:error, Error.t()}Acknowledge all pending messages
poll_queue/2(client, opts) :: {:ok, PollResponse.t()} | {:error, Error.t()}Poll with transactional control
queue_upstream/1(client) :: {:ok, QueueUpstreamHandle.t()} | {:error, Error.t()}Open an upstream stream for sending

Channel Management

FunctionSpecDescription
create_channel/3(client, name, type) :: :ok | {:error, Error.t()}Create a channel of given type
delete_channel/3(client, name, type) :: :ok | {:error, Error.t()}Delete a channel
list_channels/3(client, type, filter \\ "") :: {:ok, [ChannelInfo.t()]} | {:error, Error.t()}List channels by type
purge_queue_channel/2(client, channel) :: :ok | {:error, Error.t()}Purge all messages from a queue

Channel types: :events, :events_store, :commands, :queries, :queues

Quick Usage

main.exs
{:ok, client} = KubeMQ.Client.start_link(
  address: "localhost:50000",
  client_id: "elixir-demo"
)

{:ok, info} = KubeMQ.Client.ping(client)
IO.puts("Connected to #{info.host} v#{info.version}")

KubeMQ.Client.close(client)

See Also

Was this page helpful?

On this page