# Events Store (/sdks/kotlin/reference/events-store)



`PubSubClient` exposes `publishEventStore`, `publishEventStoreStream`, and `subscribeToEventsStore` for persisted events with configurable replay positions.

## publishEventStore [#publisheventstore]

```kotlin
suspend fun publishEventStore(message: EventStoreMessage): EventSendResult
```

Persists an event and returns acknowledgement metadata.

**Parameters:**

| Name      | Type                | Required | Description                           |
| --------- | ------------------- | -------- | ------------------------------------- |
| `message` | `EventStoreMessage` | Yes      | Built via `eventStoreMessage { }` DSL |

**Returns:** `EventSendResult` -- IDs, timestamps, and `sent` flag from the broker.

## publishEventStoreStream [#publisheventstorestream]

```kotlin
fun publishEventStoreStream(events: Flow<EventStoreMessage>): Flow<EventSendResult>
```

Streams persistent events for high-throughput publishing.

## subscribeToEventsStore [#subscribetoeventsstore]

```kotlin
fun subscribeToEventsStore(config: EventsStoreSubscriptionConfig.() -> Unit): Flow<EventMessageReceived>
```

Returns a cold `Flow` that subscribes with replay parameters.

**Configuration DSL:**

| Property        | Type            | Required | Description             |
| --------------- | --------------- | -------- | ----------------------- |
| `channel`       | `String`        | Yes      | Channel to subscribe to |
| `group`         | `String`        | No       | Consumer group          |
| `startPosition` | `StartPosition` | Yes      | Replay start position   |

## Replay options (StartPosition) [#replay-options-startposition]

| Value                                     | Description                               |
| ----------------------------------------- | ----------------------------------------- |
| `StartPosition.StartNewOnly`              | Only new events after subscription        |
| `StartPosition.StartFromFirst`            | Replay from the very first event          |
| `StartPosition.StartFromLast`             | Last event plus new ones                  |
| `StartPosition.StartAtSequence(n)`        | Replay from sequence number `n`           |
| `StartPosition.StartAtTime(nanos)`        | Replay from timestamp (nanos since epoch) |
| `StartPosition.StartAtTimeDelta(seconds)` | Replay from `seconds` ago                 |

## eventStoreMessage DSL [#eventstoremessage-dsl]

```kotlin
eventStoreMessage {
    channel = "events-store.orders"
    body = payload.toByteArray()
    metadata = "order-service"
}
```

## Quick Usage [#quick-usage]

```kotlin title="EventsStore.kt"
KubeMQClient.pubSub {
    address = "localhost:50000"
    clientId = "store-demo"
}.use { pub ->
    pub.publishEventStore(eventStoreMessage {
        channel = "audit.security"
        body = payload.toByteArray()
    })
}
```

## See Also [#see-also]

* [Events Store Examples](/sdks/kotlin/how-to/events-store/)
* [Events Store pattern](/learn/events-store/getting-started)
* [Kotlin SDK Getting Started](/sdks/kotlin)
