pub struct ConsumerContext { /* private fields */ }Expand description
Context provided to a Consumer, allowing it to send exchanges into the route.
Implementations§
Source§impl ConsumerContext
impl ConsumerContext
Sourcepub fn new(
sender: Sender<ExchangeEnvelope>,
cancel_token: CancellationToken,
route_id: String,
) -> Self
pub fn new( sender: Sender<ExchangeEnvelope>, cancel_token: CancellationToken, route_id: String, ) -> Self
Create a new consumer context wrapping the given channel sender.
The route_id identifies the route this consumer is bound to, enabling
ADR-0012 per-route metrics and health observations.
The startup signal defaults to a fresh Pending pair; the consumer
can call Self::mark_ready once it has bound its resource. For
ConsumerStartupMode::Immediate consumers the runtime ignores
the signal (it constructs an already-resolved receiver instead).
Sourcepub fn with_startup(self, startup: StartupSignal) -> Self
pub fn with_startup(self, startup: StartupSignal) -> Self
Replace the startup signal carried by this context. Used by
spawn_consumer_task to install the signal whose matching receiver
is returned to the route controller.
Sourcepub fn with_in_flight_counter(self, counter: Arc<AtomicU64>) -> Self
pub fn with_in_flight_counter(self, counter: Arc<AtomicU64>) -> Self
Install the context-global accepted-not-completed counter on this
context (drainclaim). The camel-core runtime calls this at consumer
start; afterwards every envelope sent via Self::send or
Self::send_and_wait carries an InFlightClaim. Contexts
without a counter (tests, raw fast paths) send uncounted envelopes.
Sourcepub fn in_flight_counter(&self) -> Option<Arc<AtomicU64>>
pub fn in_flight_counter(&self) -> Option<Arc<AtomicU64>>
Returns the installed accepted-not-completed counter, if any
(drainclaim). Components whose consumers dispatch through the raw
Self::sender fast path capture this once at consumer start and
mint an InFlightClaim at their acceptance-dequeue points, so raw
dispatches count exactly like Self::send (rc-nftni). Returns
None for contexts without a counter (tests) — callers mint none.
Sourcepub fn startup_signal(&self) -> StartupSignal
pub fn startup_signal(&self) -> StartupSignal
Returns a clone of the internal StartupSignal so callers (e.g.
spawn_consumer_task) can drive failure propagation independently of
the consumer’s own mark_ready() call.
Sourcepub fn mark_ready(&self)
pub fn mark_ready(&self)
Mark this consumer’s startup as complete. Only meaningful for
ConsumerStartupMode::Explicit consumers — Immediate consumers
never need to call this because the runtime resolves their startup
receiver at construction time.
Idempotent.
Sourcepub fn mark_failed(&self, err: String)
pub fn mark_failed(&self, err: String)
Mark this consumer’s startup as FAILED with err. Only meaningful for
ConsumerStartupMode::Explicit consumers whose readiness is gated on
an asynchronous event that may never arrive (e.g. Kafka partition
assignment). Calling this resolves the runtime’s startup await with a
startup error instead of hanging.
Idempotent — the first transition out of Pending wins, so a later
mark_ready() cannot override an earlier mark_failed() and vice
versa.
Sourcepub async fn cancelled(&self)
pub async fn cancelled(&self)
Returns a future that resolves when shutdown is requested.
Use in tokio::select! inside consumer loops.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Returns true if shutdown has been requested.
Sourcepub fn route_id(&self) -> &str
pub fn route_id(&self) -> &str
Returns the route_id this consumer is bound to.
Available for ADR-0012 metrics/health calls that require a route_id (categories (b′), (e), (g)). Set at construction time by the route controller when spawning the consumer task.
Sourcepub fn cancel_token(&self) -> CancellationToken
pub fn cancel_token(&self) -> CancellationToken
Returns a clone of the CancellationToken.
Useful for consumers that spawn per-request tasks and need to propagate
shutdown to each task. See HttpConsumer for an example.
Sourcepub fn sender(&self) -> Sender<ExchangeEnvelope>
pub fn sender(&self) -> Sender<ExchangeEnvelope>
Returns a clone of the channel sender for manual exchange submission.
Useful for consumers that spawn per-request tasks (e.g., HttpConsumer)
where each task independently sends exchanges into the pipeline.
For simple consumers, prefer send() or send_and_wait() instead.
Raw pushes through this sender bypass the claim minting of
Self::send; components using it MUST capture
Self::in_flight_counter once at start and attach a claim to every
envelope at their acceptance-dequeue point (rc-nftni), or their
in-flight work stays invisible to total_in_flight().
Sourcepub fn set_inline_dispatcher(&self, dispatcher: Arc<dyn InlineRouteDispatcher>)
pub fn set_inline_dispatcher(&self, dispatcher: Arc<dyn InlineRouteDispatcher>)
Publish the inline dispatch capability on this context.
Set once by the camel-core runtime before the consumer starts, when the route’s effective concurrency model permits the inline fast path.
Set-once, KEEP-FIRST contract: if a dispatcher was already published, the first one stays in place, the second call is ignored with a warning (it is not an error). All clones of this context share the same slot, so a dispatcher set through any clone is visible through all of them.
Sourcepub fn inline_dispatcher(&self) -> Option<Arc<dyn InlineRouteDispatcher>>
pub fn inline_dispatcher(&self) -> Option<Arc<dyn InlineRouteDispatcher>>
Returns the inline dispatch capability published by the camel-core
runtime, if any. See Self::set_inline_dispatcher for the
set-once-keep-first contract.
Sourcepub async fn send(&self, exchange: Exchange) -> Result<(), CamelError>
pub async fn send(&self, exchange: Exchange) -> Result<(), CamelError>
Send an exchange into the route pipeline (fire-and-forget).
Attaches an InFlightClaim when a counter is installed
(Self::with_in_flight_counter); a failed push drops the
envelope, which drops the claim and rolls the count back.
Sourcepub async fn send_and_wait(
&self,
exchange: Exchange,
) -> Result<Exchange, CamelError>
pub async fn send_and_wait( &self, exchange: Exchange, ) -> Result<Exchange, CamelError>
Send an exchange and wait for the pipeline result (request-reply).
Returns Ok(exchange) on success or Err(e) if the pipeline failed
without an error handler absorbing the error.