mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
1.9 KiB
1.9 KiB
10. js-purge
Date: 2021-06-30
Status
Accepted
Context
JetStream provides the ability to purge streams by sending a request message to:
$JS.API.STREAM.PURGE.<streamName>. The request will return a new message with
the following JSON:
{
type: "io.nats.jetstream.api.v1.stream_purge_response",
error?: ApiError,
success: boolean,
purged: number
}
The error field is an ApiError. The success field will be set to true if the request
succeeded. The purged field will be set to the number of messages that were
purged from the stream.
Options
More fine-grained control over the purge request can be achieved by specifying additional options as JSON payload.
{
seq?: number,
keep?: number,
filter?: string
}
seqis the optional upper-bound sequence for messages to be deleted (non-inclusive)keepis the maximum number of messages to be retained (might be less depending on whether the specified count is available).- The options
seqandkeepare mutually exclusive. filteris an optional subject (may include wildcards) to filter on. Only messages matching the filter will be purged.filterandseqpurges all messages matching filter having a sequence number lower than the value specified.filterandkeeppurges all messages matching filter keeping at most the specified number of messages.- If
seqorkeepis specified, butfilteris not, the stream will remove/keep the specified number of messages. - To
keepN number of messages for multiple subjects, invokepurgewith differentfilters. - If no options are provided, all messages are purged.
Consequences
Tooling and services can use this endpoint to remove messages in creative ways. For example, a stream may contain a number of samples, at periodic intervals a service can sum them all and replace them with a single aggregate.