Class: SharedBroker::Middlewares::Idempotency
- Inherits:
-
Object
- Object
- SharedBroker::Middlewares::Idempotency
- Defined in:
- lib/shared_broker/middlewares/idempotency.rb
Defined Under Namespace
Classes: MemoryStore
Instance Method Summary collapse
- #call(topic, message, metadata) ⇒ Object
-
#initialize(store: nil, expires_in: 3600) ⇒ Idempotency
constructor
A new instance of Idempotency.
Constructor Details
#initialize(store: nil, expires_in: 3600) ⇒ Idempotency
Returns a new instance of Idempotency.
26 27 28 29 |
# File 'lib/shared_broker/middlewares/idempotency.rb', line 26 def initialize(store: nil, expires_in: 3600) @store = store || MemoryStore.new @expires_in = expires_in end |
Instance Method Details
#call(topic, message, metadata) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/shared_broker/middlewares/idempotency.rb', line 31 def call(topic, , ) return yield unless [:operation] == :subscribe correlation_id = [:correlation_id] || [:_correlation_id] return yield unless correlation_id key = "shared_broker:idempotency:#{topic}:#{correlation_id}" return if duplicate?(key) mark_processed(key) yield end |