Hermes PostgreSQL
    Preparing search index...

    Function createPollingStore

    • Creates the store of the asyncOutbox table for createPollingOutbox from @chassisjs/hermes. It works with usePartitionOrderingPolicy and useNoOrderingPolicy.

      The claims use SELECT ... FOR UPDATE SKIP LOCKED, and all the times are computed with the clock of PostgreSQL.

      getLag finds the oldest undelivered message with the same skip scan and the first message of every partition, so it costs about as much as a poll.

      The partitions with undelivered messages are found with a skip scan of the asyncOutboxPendingIdx index (one index lookup per partition), so the cost of a poll does not grow with the number of undelivered messages, but it grows with the number of partitions that have them. The partitions without undelivered messages are removed from asyncOutboxPartition; the next poll adds them again when they get new messages, so a message that commits during the removal is not lost.

      markFailed changes a message only when owner still has the claim of the message, or of its partition when the message itself is not claimed (usePartitionOrderingPolicy). It locks the partition (FOR SHARE), so it waits for an instance that is claiming it and then sees the new owner.

      markDelivered does not check the claim on purpose: the message is already published, so it is delivered whoever published it. Checking the claim would only leave a published message undelivered, to be published again.

      Type Parameters

      • Message

      Parameters

      • getSql: () => HermesSql

        Returns the connection to the database

      • scope: PollingStoreScope

        The consumer and, optionally, the partition whose messages the store reads

      Returns PollingOutboxBaseStore<Message> & {
          claimMessages(
              params: { lease: Duration; limit: number; owner: string },
          ): Promise<PolledMessage<Message>[]>;
          releaseMessages(params: { owner: string }): Promise<void>;
          renewMessages(
              params: {
                  lease: Duration;
                  messages: PolledMessage<Message>[];
                  owner: string;
              },
          ): Promise<void>;
      } & {
          claimPartitions(
              params: { lease: Duration; limit: number; owner: string },
          ): Promise<string[]>;
          readPartition(
              params: { limit: number; partitionKey: string },
          ): Promise<PolledMessage<Message>[]>;
          releasePartitions(params: { owner: string }): Promise<void>;
          renewPartitions(
              params: { lease: Duration; owner: string; partitionKeys: string[] },
          ): Promise<number | void>;
      } & PollingOutboxLagStore