pub trait MessageConsumer: Send + Sync {
// Required methods
fn receive_batch<'life0, 'async_trait>(
&'life0 mut self,
_max_messages: usize,
) -> Pin<Box<dyn Future<Output = Result<ReceivedBatch, ConsumerError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn as_any(&self) -> &dyn Any;
// Provided methods
fn on_connect_hook(&self) -> Option<BoxFuture<'_, Result<()>>> { ... }
fn on_disconnect_hook(&self) -> Option<BoxFuture<'_, Result<()>>> { ... }
fn receive<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<Received, ConsumerError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
fn receive_batch_helper<'life0, 'async_trait>(
&'life0 mut self,
_max_messages: usize,
) -> Pin<Box<dyn Future<Output = Result<ReceivedBatch, ConsumerError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
fn status<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = EndpointStatus> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
}Required Methods§
Sourcefn receive_batch<'life0, 'async_trait>(
&'life0 mut self,
_max_messages: usize,
) -> Pin<Box<dyn Future<Output = Result<ReceivedBatch, ConsumerError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn receive_batch<'life0, 'async_trait>(
&'life0 mut self,
_max_messages: usize,
) -> Pin<Box<dyn Future<Output = Result<ReceivedBatch, ConsumerError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Receives a batch of messages.
This method must be implemented by all consumers.
If in doubt, implement receive_batch to return a single message as a vector.
fn as_any(&self) -> &dyn Any
Provided Methods§
Sourcefn on_connect_hook(&self) -> Option<BoxFuture<'_, Result<()>>>
fn on_connect_hook(&self) -> Option<BoxFuture<'_, Result<()>>>
Returns an optional lifecycle hook that runs once after the consumer connection is created.
The route awaits this hook before it reports itself as ready. Returning an error fails route startup and lets the outer route runner reconnect or surface the startup failure.
Use this for per-connection setup that should be shared by all messages read through this consumer, such as warming a connection pool, creating SQLite tables or indexes, setting up a Kafka consumer group, or authenticating a RabbitMQ channel.
fn on_connect_hook(&self) -> Option<BoxFuture<'_, anyhow::Result<()>>> {
Some(Box::pin(async move {
self.pool.get().await?;
self.db.execute("CREATE TABLE IF NOT EXISTS embeddings (...)").await?;
Ok(())
}))
}Sourcefn on_disconnect_hook(&self) -> Option<BoxFuture<'_, Result<()>>>
fn on_disconnect_hook(&self) -> Option<BoxFuture<'_, Result<()>>>
Returns an optional lifecycle hook that runs before the consumer is dropped.
The route awaits this hook during shutdown or reconnect cleanup. Errors are logged as warnings and do not replace the route’s original result.
Sourcefn receive<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<Received, ConsumerError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn receive<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<Received, ConsumerError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Receives a single message.
fn receive_batch_helper<'life0, 'async_trait>(
&'life0 mut self,
_max_messages: usize,
) -> Pin<Box<dyn Future<Output = Result<ReceivedBatch, ConsumerError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn status<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = EndpointStatus> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".