Define the event contract
Pass an event map toconnect() to type-check topic names and payloads:
Publish
publish() inserts an immutable event and returns the stored public representation:
Every call creates a new event ID. Pulse does not expose producer idempotency keys, so retry a failed
publish() only when your producer can tolerate the possibility of two distinct events.
Event ordering
Events are discovered by their MongoDB-assigned sequence. Retained events written before sequences were introduced usecreatedAt and UUIDv7 _id as an independent fallback cursor. Once materialized, deliveries are claimed independently and may execute concurrently.
Ordering does not span topics or consumer groups, and Pulse does not provide a single global sequence. If two producers publish at almost the same time, design the payload so your domain can detect stale updates when that matters.
Retention
Events are retained for seven days by default:expiresAt date on each new event. A TTL index with expireAfterSeconds: 0 lets MongoDB remove it asynchronously.
Use null to keep events indefinitely:
expiresAt value written when they were created. MongoDB’s TTL monitor runs in the background, so expiration is not exact to the millisecond.
Publishing before a consumer exists
The first subscription controls which retained events it sees:offsetReset: 'latest'starts after the most recent retained event at subscription creation time.offsetReset: 'earliest'starts with the oldest retained event for that topic.
offsetReset again.
Continue with Consuming events to configure offsets, concurrency, and retry behavior.