KubeMQ
Client SDKsElixirReference

Types & Errors

Shared types, subscription management, and the KubeMQ.Error exception — Elixir SDK reference.

The Elixir SDK uses Elixir exceptions and structs for rich error handling and subscription lifecycle management.

KubeMQ.Error

An exception struct with structured error information. All failed SDK operations return {:error, %KubeMQ.Error{}}.

FieldTypeDescription
codeatom()Error category
messageString.t()Human-readable error description
operationString.t()The operation that failed
channelString.t()Channel involved (if applicable)
causeterm()Underlying error cause
retryable?boolean()Whether the operation can be retried
request_idString.t()Associated request ID

Error Codes

CodeRetryableWhen
:transientYesTemporary server or network issue
:timeoutYesDeadline exceeded
:throttlingYesRate limit hit
:authenticationNoInvalid credentials
:authorizationNoInsufficient permissions
:validationNoInvalid parameters
:not_foundNoChannel or resource not found
:fatalNoUnrecoverable server error

Error Factories

KubeMQ.Error.transient("network timeout", operation: "connection.send_event")
KubeMQ.Error.timeout("deadline exceeded", operation: "client.send_command")
KubeMQ.Error.validation("channel is required", operation: "client.send_event")
KubeMQ.Error.authentication("invalid token", operation: "client.connect")

KubeMQ.Subscription

Manages an active subscription. Returned by all subscribe_to_* functions.

FunctionSpecDescription
cancel/1(Subscription.t()) :: :okCancel the subscription
active?/1(Subscription.t()) :: boolean()Check if still active
{:ok, sub} = KubeMQ.Client.subscribe_to_events(client, "ch",
  on_event: fn e -> IO.puts(e.body) end)

KubeMQ.Subscription.active?(sub)  # true
KubeMQ.Subscription.cancel(sub)
KubeMQ.Subscription.active?(sub)  # false

KubeMQ.ServerInfo

Returned by KubeMQ.Client.ping/1.

FieldTypeDescription
hostString.t()Server hostname
versionString.t()Server version
server_start_timeinteger()Server start timestamp
server_up_time_secondsinteger()Server uptime in seconds

KubeMQ.ChannelInfo

Returned by KubeMQ.Client.list_channels/3.

FieldTypeDescription
nameString.t()Channel name
typeString.t()Channel type (e.g., "events", "queues")
last_activityinteger()Last activity timestamp
is_activeboolean()Whether the channel is active
incominginteger()Incoming message count
outgoinginteger()Outgoing message count

Pattern Matching

case KubeMQ.Client.send_event(client, event) do
  :ok ->
    IO.puts("Sent!")

  {:error, %KubeMQ.Error{code: :timeout, retryable?: true}} ->
    IO.puts("Timed out — safe to retry")

  {:error, %KubeMQ.Error{code: :validation, message: msg}} ->
    IO.puts("Invalid input: #{msg}")

  {:error, %KubeMQ.Error{} = err} ->
    IO.puts("Error: #{Exception.message(err)}")
end

See Also

Was this page helpful?

On this page