Events and subscribers
Let multiple features subscribe to a business fact and inspect delivery for each subscriber.
Publish an event when several features react to the same business fact. Persistent events track each subscriber separately. For one known operation, use a job.
Publish a fact that has already happened
When a business change leads to several follow-up actions, let the publisher describe the fact, such as “article updated.” Subscribers can independently schedule SEO work, index updates, or other processing. This is a design example. Check for a suitable existing event in the feature before introducing another event for the same change.
Declare the event with defineEvent and subscribers with defineEventSubscriber. Wire definitions and handlers into the background assembly. Obtain the capability with app.event(), then use publish({ event, payload, dedupeKey }) for a registered persistent event.
Choose how to deliver it
A persistent event records the event and one delivery per subscriber. If an event was published and a single follow-up is missing, inspect that subscriber’s result. Direct events use the queue transport without a durable delivery record. The heartbeat cannot redeliver one after a process interruption. A persistent publish call can also specify firstAttempt: "inline" to make the publisher wait for initial attempts, with queue retries for subsequent failures.
Retain payload decoding for versions still being delivered. Test two subscribers with one failing. For a handler whose side effects could run twice, define how replay should be handled before enabling automatic recovery. Queues and jobs · Schedules