Interface WeixinStateStore


public interface WeixinStateStore
Account-scoped state for at-least-once message processing. Implementations must atomically validate the unexpired lease on every mutation. External Agent and provider side effects are not part of this transaction and can be repeated after a crash.
  • Method Details

    • loadCursor

      String loadCursor(String accountId)
    • loadContextToken

      String loadContextToken(String accountId, String peerId)
    • saveContextToken

      boolean saveContextToken(String accountId, WeixinLease lease, String peerId, String token)
    • acquireLease

      Optional<WeixinLease> acquireLease(String accountId, String holderId, long leaseMs)
      A released or expired lease must never reuse its generation, even for the same holder.
    • renewLease

      boolean renewLease(String accountId, WeixinLease lease, long leaseMs)
    • isLeaseCurrent

      boolean isLeaseCurrent(String accountId, WeixinLease lease)
    • releaseLease

      void releaseLease(String accountId, WeixinLease lease)
    • acceptBatch

      boolean acceptBatch(String accountId, WeixinLease lease, String nextCursor, List<WeixinInboxMessage> messages)
      Saves the whole batch and its cursor in one transaction, deduplicating message IDs.
    • claimMessages

      List<WeixinInboxClaim> claimMessages(String accountId, WeixinLease lease, int limit, long claimMs)
      Claims in reception order. A new lease may immediately recover the previous owner's work.
    • completeMessage

      boolean completeMessage(String accountId, WeixinLease lease, WeixinInboxClaim claim)
      Only the exact, unexpired claim may finish. Completed payloads must be removed.
    • failMessage

      boolean failMessage(String accountId, WeixinLease lease, WeixinInboxClaim claim)
    • abandonMessage

      boolean abandonMessage(String accountId, WeixinLease lease, WeixinInboxClaim claim)
      Drops a claimed message the consumer will not retry again — the dispatch kept failing, or the provider kept refusing the reply. The message is tombstoned so a re-delivered batch cannot resurrect it, but it is not reported as completed.
    • removeAccount

      default void removeAccount(String accountId)
      Forgets everything held for accountId: cursor, peer context tokens and inbox.

      Hosts call this when an account is retired so a long-lived process does not accumulate state for accounts it no longer serves. Implementations that hold no per-account state can leave the default no-op.

    • inMemory

      static WeixinStateStore inMemory()