KubeMQ
Client SDKsRubyReference

Events

KubeMQ Ruby SDK API reference for real-time fire-and-forget event pub/sub.

EventMessage

Outbound event message for fire-and-forget pub/sub. Events are not persisted — use EventStoreMessage for durable delivery.

msg = KubeMQ::PubSub::EventMessage.new(
  channel: "notifications.email",
  metadata: "user-signup",
  body: '{"user_id": 42}',
  tags: { "priority" => "high" }
)

Attributes

AttributeTypeDefaultDescription
idStringAuto-generated UUIDUnique message identifier
channelStringRequiredTarget channel name
metadataStringnilArbitrary metadata string
bodyStringnilMessage payload (binary-safe)
tagsHash{String => String}{}User-defined key-value tags

EventsSubscription

Configuration for subscribing to real-time events. Supports wildcard channels (* and >) and consumer groups.

sub = KubeMQ::PubSub::EventsSubscription.new(
  channel: "events.>",
  group: "workers"
)

Attributes

AttributeTypeDefaultDescription
channelStringRequiredChannel name or wildcard pattern
groupStringnilConsumer group for load-balanced delivery

PubSubClient Methods

send_event(message)

Sends a single event. Fire-and-forget semantics.

result = client.send_event(msg)
puts "Sent: #{result.id}" if result.sent

Returns: EventSendResult

Raises: ValidationError, ClientClosedError, ConnectionError

subscribe_to_events(subscription, cancellation_token:, on_error:, &block)

Subscribes to real-time events on a channel. Runs on a background thread with automatic reconnection.

token = KubeMQ::CancellationToken.new
sub = KubeMQ::PubSub::EventsSubscription.new(channel: "events.>")

subscription = client.subscribe_to_events(sub, cancellation_token: token) do |event|
  puts "#{event.channel}: #{event.body}"
end

token.cancel
subscription.wait(5)

Parameters:

ParameterTypeDescription
subscriptionEventsSubscriptionChannel and group configuration
cancellation_tokenCancellationTokenToken for cooperative cancellation (auto-created if nil)
on_errorProcCallback receiving Error on stream failures
&blockBlockCalled for each received event

Yields: EventReceived with channel, metadata, body, tags, and id attributes.

Returns: Subscription handle to check status, cancel, or join.

create_events_sender(on_error:)

Creates a streaming event sender for high-throughput publishing.

sender = client.create_events_sender
sender.publish(msg)
sender.close

Returns: PubSub::EventSender

EventReceived

Inbound event received in a subscription callback.

AttributeTypeDescription
idStringMessage identifier
channelStringChannel the event arrived on
metadataStringMetadata string
bodyStringMessage payload
tagsHashKey-value tags

EventSendResult

Result returned from send_event.

AttributeTypeDescription
idStringMessage identifier
sentBooleanWhether the event was accepted
errorStringError message (if any)

Was this page helpful?

On this page