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.
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