Skip to main content

Subscribe to a topic

The handler receives: 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 same consumerGroup and declare the same persisted subscription options:
The unique delivery key is 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:
For one consumer group and topic:
  • 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.
This provides processing order, not a transaction that spans the handler and external systems.

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:
Configure it per subscription:
After the final error, Pulse marks the delivery terminal and continues. Errors are persisted with a code, name, message, and stack when available.

At-most-once attempts

To disable handler retries:
At-most-once always resolves 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 each consumerGroup + topic:
  • ordered
  • offsetReset
  • delivery
  • maxRetries
  • retryDelayMs
  • retryBackoffMultiplier
Every replica must provide matching values. A mismatch throws 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.