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 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.
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).
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.
Trait Implementations§
Source§impl Clone for ConsumerContext
impl Clone for ConsumerContext
Source§fn clone(&self) -> ConsumerContext
fn clone(&self) -> ConsumerContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more