Back to Kurrentdb

Persistent subscriptions

docs/server/http-api/persistent.md

26.1.013.8 KB
Original Source

Persistent subscriptions

This document explains how to use the HTTP API for setting up and consuming persistent subscriptions and competing consumer subscription groups. For an overview on competing consumers and how they relate to other subscription types, please see our getting started guide.

::: tip The Administration UI includes a Persistent Subscriptions section where you are able to create, update, delete and view subscriptions and their statuses. :::

Creating a persistent subscription

Before interacting with a subscription group, you need to create one. This requires admin permissions. You will get an error if you try to create a subscription group more than once.

::: warning Persistent subscriptions to $all are not supported over the HTTP API. If you want to create persistent subscriptions to $all, use the appropriate client method. :::

<!-- TODO: File inclusion for the below? -->
URISupported Content TypesMethod
/subscriptions/{stream}/{subscription_name}application/jsonPUT

Query parameters

ParameterDescription
streamThe stream the persistent subscription is on.
subscription_nameThe name of the subscription group.

Body

ParameterDescription
resolveLinktosTells the subscription to resolve link events.
startFromStart the subscription from the position of the event in the stream.
extraStatisticsTells the backend to measure timings on the clients so statistics will contain histograms of them.
checkPointAfterMillisecondsThe amount of time the system should wait before trying to checkpoint.
liveBufferSizeThe size of the live buffer (in memory) before resorting to paging.
readBatchSizeThe size of the read batch when in paging mode.
bufferSizeThe number of messages that should be buffered when in paging mode.
maxCheckPointCountThe maximum number of messages not checkpointed before forcing a checkpoint.
maxRetryCountSets the number of times a message should be retried before it is considered a bad message.
maxSubscriberCountSets the maximum number of allowed TCP subscribers.
messageTimeoutMillisecondsSets the timeout for a client before the message will be retried.
minCheckPointCountThe minimum number of messages to write a checkpoint for.
namedConsumerStrategyAllowed values are RoundRobin, DispatchToSingle, Pinned, PinnedByCorrelation.

Updating a persistent subscription

You can edit the settings of an existing subscription while it is running. This drops the current subscribers and resets the subscription internally. This requires admin permissions.

URISupported Content TypesMethod
/subscriptions/{stream}/{subscription_name}application/jsonPOST

::: warning Persistent subscriptions to $all are not supported over the HTTP API. To update persistent subscriptions to $all, use the appropriate client method. :::

Query parameters

ParameterDescription
streamThe stream the persistent subscription is on.
subscription_nameThe name of the subscription group.

Body

Same parameters as Creating a Persistent Subscription.

Deleting a persistent subscription

URISupported Content TypesMethod
/subscriptions/{stream}/{subscription_name}application/jsonDELETE

::: warning Deleting persistent subscriptions to $all is not supported over the HTTP API. If you want to delete persistent subscriptions to $all, use the appropriate client method. :::

Query parameters

ParameterDescription
streamThe stream the persistent subscription is on.
subscription_nameThe name of the subscription group.

Reading a stream via a persistent subscription

By default, reading a stream via a persistent subscription returns a single event per request and does not embed the event properties as part of the response.

URISupported Content TypesMethod
/subscriptions/{stream}/{subscription_name}application/vnd.eventstore.competingatom+json, application/vnd.eventstore.competingatom+xmlGET
/subscriptions/{stream}/{subscription_name}?embed={embed}application/vnd.eventstore.competingatom+json, application/vnd.eventstore.competingatom+xmlGET
/subscriptions/{stream}/{subscription}/{count}?embed={embed}application/vnd.eventstore.competingatom+json, application/vnd.eventstore.competingatom+xmlGET

Query parameters

ParameterDescription
streamThe stream the persistent subscription is on.
subscription_nameThe name of the subscription group.
countHow many events to return for the request.
embedAllowed values are None, Content, Rich, Body, PrettyBody, TryHarder.

See Reading Streams for information on the different embed levels.

Response

@code

Acknowledgements

Clients must acknowledge (or not acknowledge) messages in the competing consumer model. If processing is successful, send an ack (acknowledge) to the server to let it know that the message has been handled. If processing fails, then you can nack (not acknowledge) the message and tell the server how to handle the failure. If the client fails to respond in the given timeout period, the message is retried. You should use the rel links in the feed for acknowledgements rather than bookmark URIs, as they are subject to change in future versions.

For example:

json
{
  "uri": "https://localhost:2113/subscriptions/teststream1/testgroup-1/ack/33635881-5881-5881-5881-175033635881",
  "relation": "ack",
  "type": null
},

Ack multiple messages

URISupported Content TypesMethod
/subscriptions/{stream}/{subscription_name}/ack?ids={messageids}application/jsonPOST

Query parameters

ParameterDescription
streamThe stream the persistent subscription is on.
subscription_nameThe name of the subscription group.
messagesThe IDs of the messages that needs to be acknowledged.

Ack a single message

URISupported Content TypesMethod
/subscriptions/{stream}/{subscription_name}/ack/{messageid}application/jsonPOST

Query parameters

ParameterDescription
streamThe stream the persistent subscription is on.
subscription_nameThe name of the subscription group.
messageidThe ID of the message that needs to be acknowledged.

Nack multiple messages

URISupported Content TypesMethod
/subscriptions/{stream}/{subscription_name}/nack?ids={messageids}?action={action}application/jsonPOST

Query parameters

ParameterDescription
streamThe stream the persistent subscription is on.
subscription_nameThe name of the subscription group.
action<ul><li>Park: Don't retry the message; park it until a request is sent to replay the parked messages.</li><li>Retry: Retry the message.</li><li>Skip: Discard the message.</li></ul>
messageidThe ID of the message that needs to be nacked.

Nack a single message

URISupported Content TypesMethod
/subscriptions/{stream}/{subscription_name}/nack/{messageid}?action={action}application/jsonPOST

Replaying parked messages

URISupported Content TypesMethod
/subscriptions/{stream}/{subscription_name}/replayParkedapplication/jsonPOST

Getting information for all subscriptions

URIMethod
/subscriptionsGET

Response

@code

Getting information for a page of subscriptions

When a count is specified, the response includes the paging information for the request.

URIMethod
/subscriptions?count={count}&offset={offset}GET

Query parameters

ParameterDescription
countThe number of streams to get the persistent susbcriptions groups for. Used for paging, omit to get all streams.
offsetThe number of streams to skip when getting persistent subscription groups. Used for paging.

Response

@code

Get subscriptions for a stream

URISupported Content TypesMethod
/subscriptions/{stream}application/jsonGET

Response

@code

Getting a specific subscription

URISupported Content TypesMethod
/subscriptions/{stream}/{subscription_name}/infoapplication/jsonGET

Response

@code

<!-- TODO: Is this better as a general subscriptions page? --> <!-- TODO: Somehow get this better integrated with API docs -->