SQLStreams

the messaging platform that is just Postgres

You last visited on 9999-99-99 Show what's new since then

List messages for a key

Edit this page
Stream · Related pages
Posted: 2026-09-16 · Report this thread
brandon Site Admin brandon profile Posts: 96
Messages(ctx context.Context, limit int) ([]*StoredMessage[T], error)

Reads retained messages with the selected MessageKey, newest id first. Results include uncompacted messages and older compacted messages that remain in the log. The read does not filter by payload schema version.

Example

Inspect the order-123 message key on the payments.requested stream using an initialized client. RawPayload preserves JSON from any version.

payments := client.Stream[sqlstreams.RawPayload]("payments.requested")
messages, err := payments.Key("order-123").Messages(ctx, 20)
if err != nil {
return err
}
for _, message := range messages {
fmt.Println(message.Id, string(*message.Message))
}

Parameters

Parameter Type Required Description
ctx context.Context Yes Cancellation or its deadline interrupts the read.
limit int Yes Maximum messages to return. Must be positive. There is no default in the Go API.

Returns

Condition Return value
Matching retained messages exist (messages, nil), containing stored messages in descending id order.
No matching messages remain (messages, nil), where len(messages) == 0.
Stream is absent or read fails (nil, err).

CLI

sqlstreams stream key messages payments.requested order-123 --limit 20

The CLI defaults to a limit of 20. --output json prints an array of stored messages, or [] when no matching messages remain.

Errors

Error When
Validation error A stream name or message key is empty, or limit is not positive.
ErrStreamNotFound The stream is not registered.
JSON decoding error A stored payload cannot be decoded into T.
Database or context error The read fails or is interrupted.