Hermes MySQL
    Preparing search index...

    Function createReactionConsumer

    • Creates a consumer that runs a reaction (defineHermesReaction) on the events it handles, e.g. so that one module reacts to the events of another one.

      The events of a stream are handled one by one, in their order, by one instance at a time; there is no order between streams. The handler gets the transaction (tx, READ COMMITTED) that moves the checkpoint of the reaction past the event, so what it does in it, e.g. an append with { tx }, commits together with the checkpoint, or not at all, and is not done twice. The work done outside of tx (e.g. a call of an HTTP API) is done at least once, so make it idempotent, e.g. by eventId.

      A handler that throws (including a VersionConflictError of an append in tx, which a command handler does not retry in a transaction) rolls everything back, and the event is handled again after the retry delay; the events after it in its stream wait until then. With maxAttempts, the last failing attempt writes the event to hermes_dead_letters (the dead letter queue) and skips it instead; onGiveUp can keep the stream waiting by throwing. The events the reaction does not handle only move its checkpoint.

      Parameters

      Returns EventStoreConsumer

      const stop = await createReactionConsumer({
      reaction: chargeOnTaskCompleted,
      getOptions: () => ({ uri: process.env.MYSQL_URL }),
      }).start()