Class IdempotencyStore
java.lang.Object
io.agentscope.extensions.channel.common.IdempotencyStore
- All Implemented Interfaces:
InboundEventDeduplicator
Bounded in-process implementation of
InboundEventDeduplicator. Webhook providers
(notably WeCom) commonly retry the same message id under failure; this store de-duplicates by
msgId.
Internal map is bounded to maxEntries — when full, entries are evicted to make
room: expired entries are dropped first, after which the victim is unspecified. Entries are
also lazily expired after ttlMillis.
State lives in the JVM heap, so deduplication only holds within a single process; see InboundEventDeduplicator for multi-instance deployments. This class is thread-safe.
-
Constructor Summary
ConstructorsConstructorDescriptionDefault 5-minute TTL, 10k entries — sufficient for any single channel's retry burst.IdempotencyStore(long ttlMillis, int maxEntries) -
Method Summary
-
Constructor Details
-
IdempotencyStore
public IdempotencyStore()Default 5-minute TTL, 10k entries — sufficient for any single channel's retry burst. -
IdempotencyStore
public IdempotencyStore(long ttlMillis, int maxEntries)
-
-
Method Details
-
firstSeen
Recordskeyas seen. Returnstruewhenkeyhas not been observed within the TTL (the caller should proceed),falsewhen it is a redelivery. An accepted observation restarts the key's retention window, so after the TTL lapses only the first redelivery proceeds and the rest are still dropped.- Specified by:
firstSeenin interfaceInboundEventDeduplicator- Parameters:
key- opaque deduplication key composed by the caller;nullis treated as always first-seen- Returns:
truewhenkeyhas not been observed within the implementation's retention horizon and the caller should process the event;falsewhen it is a redelivery and must be dropped
-
size
public int size()Returns the current size; mostly for tests/observability.
-