# Streams Client

Accessed via `client.Streams()` on the [Hatchet client](/reference/go/client).

## StreamsClient

StreamsClient publishes to and reads from durable topics. Unlike ctx.PutStream streams, topics are stored, independent of any run, and readers can resume from a cursor.

Methods:

Name, Description

`Events`, Events streams topic's messages from the start or WithCursor.
`Publish`, Publish returns once the message is stored.

### Functions

#### `Events`

Events streams topic's messages from the start or WithCursor. The channel closes when ctx ends, the connection drops or the server hangs up; to continue, call Events again with the last event's Cursor.

```go
func (s *StreamsClient) Events(ctx context.Context, topic string, opts ...StreamCallOpt) <-chan StreamEvent
```

Parameters:

Name, Type

`ctx`, `context.Context`
`topic`, `string`
`opts`, `...StreamCallOpt`

Returns:

Type

`<-chan StreamEvent`

#### `Publish`

Publish returns once the message is stored. A topic is created on first publish. A client's messages to a topic are delivered in the order they were stored.

```go
func (s *StreamsClient) Publish(ctx context.Context, topic string, message []byte, opts ...StreamCallOpt) error
```

Parameters:

Name, Type

`ctx`, `context.Context`
`topic`, `string`
`message`, `[]byte`
`opts`, `...StreamCallOpt`

Returns:

Type

`error`

## Related types

### StreamEvent

StreamEvent is a stored message. Its Cursor resumes Events right after it.

Fields:

Name, Type, Description

`Payload`, `[]byte`
`Cursor`, `string`
`CreatedAt`, `time.Time`

### StreamCallOpt

StreamCallOpt configures a call to StreamsClient.Publish or StreamsClient.Events.

#### Functions

##### `WithCursor`

WithCursor resumes Events after the StreamEvent the cursor came from. Without it, Events starts at the oldest retained message. Ignored by Publish.

```go
func WithCursor(cursor string) StreamCallOpt
```

Parameters:

Name, Type

`cursor`, `string`

Returns:

Type

`StreamCallOpt`

##### `WithNamespace`

WithNamespace sets the namespace; the default is "".

```go
func WithNamespace(namespace string) StreamCallOpt
```

Parameters:

Name, Type

`namespace`, `string`

Returns:

Type

`StreamCallOpt`
