Subscribe to a topic
A Pulse instance can have one local handler per topic. Create separate Pulse instances if one process intentionally needs two independent consumer groups.
Consumer groups and replicas
All replicas of one service must use the sameconsumerGroup and declare the same persisted subscription options:
consumerGroup + eventId. Multiple replicas compete through leases, so only one replica owns an attempt at a time.
To run a second independent responsibility, use another group:
Initial offsets
offsetReset is used only when Pulse creates the durable consumerGroup + topic subscription:
The cursor is saved after Pulse materializes deliveries. Restarting a service resumes that cursor.
unsubscribe() removes only the local handler; it does not delete the subscription or reset its offset.
Pulse v1 intentionally has no administrative offset reset or replay API. Use a new consumer group when a new independent pass over retained events is appropriate.
Ordered delivery
Ordered mode is the default:- Only one handler runs at a time across all replicas.
- The next event waits while the current event is running.
- The next event also waits while a failed event is waiting for its retry.
- A terminal error is recorded and then ordering continues with the next event.
Concurrent delivery
Use concurrent mode for independent events:maxConcurrency limits running handlers for that topic in the current process. Total concurrency also depends on workerCount and the number of replicas. It is a local execution limit and is not part of the durable subscription configuration.
Retries
The default mode is at-least-once with an initial attempt and three retries:
The delay after attempt
n is:
At-most-once attempts
To disable handler retries:maxRetries to zero. Passing a positive maxRetries with this mode is a configuration error.
This means one handler attempt per delivery. It does not make external side effects exactly-once: a process can still disappear at any point, and remote systems can accept a request without returning its response.
Persisted configuration
Pulse persists these options for eachconsumerGroup + topic:
orderedoffsetResetdeliverymaxRetriesretryDelayMsretryBackoffMultiplier
PulseConfigurationError instead of silently changing delivery semantics. maxConcurrency remains local to each process.
Inspect and stop subscriptions
getSubscriptions() is synchronous and reports local subscriptions. unsubscribe() is idempotent and preserves the durable MongoDB subscription. close() stops workers and Change Streams, waits for their loops to settle, and closes the MongoDB client.
Read Reliability and recovery before writing handlers that perform external side effects.