Events
Fire-and-forget pub/sub — KubeMQ Go SDK reference.
Real-time events are delivered at most once. Use SendEvent for publishers and SubscribeToEvents for consumers; consumer groups load-balance deliveries across subscribers.
SendEvent
func (c *Client) SendEvent(ctx context.Context, event *Event) errorPublishes a fire-and-forget event. Errors reflect transport or validation only (not subscriber presence).
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
ctx | context.Context | Yes | Deadline for the send RPC |
event | *Event | Yes | Message with channel, body/metadata, optional tags |
Returns: error — nil on successful broker accept.
Throws: *KubeMQError — validation, timeout, auth, or transient failures.
Note: Delivery to subscribers is asynchronous; a nil return means the broker accepted the message.
SubscribeToEvents
func (c *Client) SubscribeToEvents(ctx context.Context, channel, group string, opts ...SubscribeOption) (*Subscription, error)Subscribes to live events on channel. Use a non-empty group for competing consumers; use "" to broadcast within the process only.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
ctx | context.Context | Yes | Subscription lifetime |
channel | string | Yes | Events channel name |
group | string | No | Consumer group for load balancing |
opts | ...SubscribeOption | No | Throttling, buffer size, callbacks |
Returns: *Subscription — call Unsubscribe to stop.
EventMessage shape
Build events with NewEvent() and setters (SetChannel, SetBody, SetMetadata, SetTags), or populate an Event struct directly.
| Field / setter | Description |
|---|---|
Channel | Target channel (required) |
Body | Binary payload |
Metadata | UTF-8 metadata string |
Tags | String map for routing or filtering |
Quick Usage
event := kubemq.NewEvent()
event.SetChannel("events.a")
event.SetBody([]byte("hello"))
if err := client.SendEvent(ctx, event); err != nil {
return err
}See Also
Was this page helpful?