pub struct IdempotentConsumerSegment { /* private fields */ }Expand description
Outcome-aware Idempotent Consumer segment.
Wraps a child sub-pipeline (OutcomeSegment) and a named
IdempotentRepository. On each exchange:
- Extract message-id via
message_id(&exchange).None→ resolve the exchange throughon_missing_key(OnMissingKey::Failfails the step,OnMissingKey::Processwarns and forwards to the child). - Pending-rollback recovery, before any repository read: a key already in flight fails loudly; a pending key is taken atomically and its removal retried. On removal failure the key returns to pending and the step fails with the removal error.
- Check
repo.contains(&key):Ok(true)→ duplicate, returnCompleted(exchange)(skip child).Ok(false)→ proceed.Err(e)→Failed(e)(contract C1).
- If
eager:repo.add(&key)before child.Ok(false)= race duplicate →Completed.Err→Failed. - Run child pipeline.
- Post-child:
Completed+ non-eager →repo.add(&key)(best-effort).Stopped→ no add (pipeline terminating).Failed+eager+remove_on_failure→repo.remove(&key); a failed removal queues the key for pending-rollback recovery.
The in-flight marker is cleared as soon as the reservation step resolves
(the pre-child add in eager mode, the post-child add/no-add in lazy
mode), so a settled key never remains in flight.
§Eager mode + Stopped
In eager mode, the key is added BEFORE the child pipeline runs. If the child
returns Stopped, the key remains registered — subsequent deliveries of the
same message ID are treated as duplicates and return Completed immediately.
This is intentional: a Stop indicates the route chose to terminate, and
re-processing the same message would be incorrect.
Implementations§
Source§impl IdempotentConsumerSegment
impl IdempotentConsumerSegment
Sourcepub fn new(
repository: Arc<dyn IdempotentRepository>,
message_id: MessageIdSource,
child_pipeline: OutcomeSegment,
eager: bool,
remove_on_failure: bool,
on_missing_key: OnMissingKey,
rt: Arc<dyn RuntimeObservability>,
) -> Self
pub fn new( repository: Arc<dyn IdempotentRepository>, message_id: MessageIdSource, child_pipeline: OutcomeSegment, eager: bool, remove_on_failure: bool, on_missing_key: OnMissingKey, rt: Arc<dyn RuntimeObservability>, ) -> Self
Build a new segment from a resolved repository, message-id extractor, child sub-pipeline, and behaviour flags.
Trait Implementations§
Source§impl Clone for IdempotentConsumerSegment
impl Clone for IdempotentConsumerSegment
Source§impl OutcomePipeline for IdempotentConsumerSegment
impl OutcomePipeline for IdempotentConsumerSegment
Source§fn clone_box(&self) -> Box<dyn OutcomePipeline>
fn clone_box(&self) -> Box<dyn OutcomePipeline>
Box<dyn OutcomePipeline> cannot directly derive Clone.