# Events (/sdks/go/reference/events)



Real-time events are delivered at most once. Use `SendEvent` for publishers and `SubscribeToEvents` for consumers; consumer groups load-balance deliveries across subscribers.

## SendEvent [#sendevent]

```go
func (c *Client) SendEvent(ctx context.Context, event *Event) error
```

Publishes 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 [#subscribetoevents]

```go
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 [#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 [#quick-usage]

```go title="events.go"
event := kubemq.NewEvent()
event.SetChannel("events.a")
event.SetBody([]byte("hello"))

if err := client.SendEvent(ctx, event); err != nil {
    return err
}
```

## See Also [#see-also]

* [Events Examples](/sdks/go/how-to/events/)
* [Events pattern](/learn/events/getting-started)
* [Go SDK Getting Started](/sdks/go)
