pub struct MessageHandlerBuilder<Context, Error>{ /* private fields */ }Expand description
A builder to compose a MessageHandler with a fluent API.
Use MessageHandler::builder as entrypoint.
Implementations§
Source§impl<Context, Error> MessageHandlerBuilder<Context, Error>
impl<Context, Error> MessageHandlerBuilder<Context, Error>
Sourcepub fn with_prefetch_count(self, prefetch_count: u16) -> Self
pub fn with_prefetch_count(self, prefetch_count: u16) -> Self
Configure the prefetch count of the handler. If not configured, the handler inherits the prefetch count configured at the consumer group level.
Sourcepub fn with_consume_options(self, consume_options: BasicConsumeOptions) -> Self
pub fn with_consume_options(self, consume_options: BasicConsumeOptions) -> Self
To configure the consume options for the handler. If not configured, the handler inherits the prefetch count configured at the consumer group level.
Sourcepub fn with_processing_middleware<M: ProcessingMiddleware<Context, Error>>(
self,
middleware: M,
) -> Self
pub fn with_processing_middleware<M: ProcessingMiddleware<Context, Error>>( self, middleware: M, ) -> Self
You can add processing middleware to inject logic before and after the handler logic.
Middlewares are executed in the order they are registered: the first registered middleware executes first on the way in and last on the way out.
Processing middlewares registered at the MessageHandler level are executed AFTER
processing middlewares registered at the ConsumerGroup level.
Check out ProcessingMiddleware’s documentation for more details.
Sourcepub fn with_dyn_processing_middleware(
self,
middleware: Arc<dyn ProcessingMiddleware<Context, Error>>,
) -> Self
pub fn with_dyn_processing_middleware( self, middleware: Arc<dyn ProcessingMiddleware<Context, Error>>, ) -> Self
Append dynamic processing middleware logic, see MessageHandlerBuilder::with_processing_middleware.
Sourcepub fn with_processing_middlewares<I>(self, middlewares: I) -> Self
pub fn with_processing_middlewares<I>(self, middlewares: I) -> Self
Append multiple dynamic processing middlewares, see MessageHandlerBuilder::with_processing_middleware.
Sourcepub fn with_telemetry_middleware<M: TelemetryMiddleware<Context, Error>>(
self,
middleware: M,
) -> Self
pub fn with_telemetry_middleware<M: TelemetryMiddleware<Context, Error>>( self, middleware: M, ) -> Self
You can add telemetry middleware to inject logic before and after the message processing has taken place.
Telemetry middlewares are executed before all processing middlewares and the handler. Telemetry middlewares are executed in the order they are registered: the first registered telemetry middleware executes first on the way in and last on the way out.
Telemetry middlewares registered at the MessageHandler level are executed AFTER
telemetry middlewares registered at the ConsumerGroup level.
Telemetry middlewares registered at the MessageHandler level are executed BEFORE
processing middlewares registered at the ConsumerGroup level and MessageHandler level.
Check out TelemetryMiddleware’s documentation for more details.
Sourcepub fn with_dyn_telemetry_middleware(
self,
middleware: Arc<dyn TelemetryMiddleware<Context, Error>>,
) -> Self
pub fn with_dyn_telemetry_middleware( self, middleware: Arc<dyn TelemetryMiddleware<Context, Error>>, ) -> Self
Append dynamic telemetry middleware logic, see MessageHandlerBuilder::with_telemetry_middleware.
Sourcepub fn with_telemetry_middlewares<I>(self, middlewares: I) -> Self
pub fn with_telemetry_middlewares<I>(self, middlewares: I) -> Self
Append multiple dynamic telemetry middlewares, see MessageHandlerBuilder::with_telemetry_middleware.
Sourcepub fn with_pre_start_hook<H: ConsumerPreStartHook>(self, hook: H) -> Self
pub fn with_pre_start_hook<H: ConsumerPreStartHook>(self, hook: H) -> Self
Pre-start hooks are executed before consumers start pulling messages from queues. Pre-start hooks are used to execute setup logic for resources against the message broker - e.g. create exchanges, bind queues, etc.
Check out ConsumerPreStartHook’s documentation
for more details.
If no pre-start hook is specified at the MessageHandler level, the hook
specified at the ConsumerGroup level is executed.
Sourcepub fn with_pre_start_hooks<I>(self, hooks: I) -> Self
pub fn with_pre_start_hooks<I>(self, hooks: I) -> Self
Append multiple pre-start hooks, see MessageHandlerBuilder::with_pre_start_hook.
Sourcepub fn with_priority(self, priority: i32) -> Self
pub fn with_priority(self, priority: i32) -> Self
Consumer priorities allow you to ensure that high priority consumers receive messages while they are active, with messages only going to lower priority consumers when the high priority consumers block.
Sets the x-priority consume argument.
See https://www.rabbitmq.com/consumer-priority.html#how-to-use.
Default not specified, equivalent to 0.
Sourcepub fn transient_error_hook<H: ConsumerTransientErrorHook>(
self,
hook: H,
) -> Self
pub fn transient_error_hook<H: ConsumerTransientErrorHook>( self, hook: H, ) -> Self
A transient error hook allows you to customise the behaviour of the message handlers when the processing of an incoming message fails with an error classified as transient - e.g. retryable.
Check out ConsumerTransientErrorHook’s
documentation for more details.
If no transient error hook is specified at the MessageHandler level, the hook
specified at the ConsumerGroup level is executed.
Sourcepub fn dyn_transient_error_hook(
self,
hook: Arc<dyn ConsumerTransientErrorHook>,
) -> Self
pub fn dyn_transient_error_hook( self, hook: Arc<dyn ConsumerTransientErrorHook>, ) -> Self
A version of MessageHandlerBuilder::transient_error_hook for already Arc-ed hooks.
Useful for sharing !Clone hooks.
§Example
let hook: Arc<dyn ConsumerTransientErrorHook>; // some dynamic shared error hook
message_handler_builder.dyn_transient_error_hook(Arc::clone(&hook));
other_message_handler_builder.dyn_transient_error_hook(hook);Sourcepub fn handler<H: Handler<Context = Context, Error = Error>>(
self,
handler: H,
) -> MessageHandler<Context, Error>
pub fn handler<H: Handler<Context = Context, Error = Error>>( self, handler: H, ) -> MessageHandler<Context, Error>
The handler used to process incoming messages.
Check out Handler’s documentation for more details.
Passing in the handler finalises the MessageHandler construction - you will
not be able to register additional middlewares or hooks after having specified the handler.
Sourcepub fn arc_handler(
self,
handler: Arc<dyn Handler<Context = Context, Error = Error>>,
) -> MessageHandler<Context, Error>
pub fn arc_handler( self, handler: Arc<dyn Handler<Context = Context, Error = Error>>, ) -> MessageHandler<Context, Error>
The Arc<handler> used to process incoming messages.
Check out Handler’s documentation for more details.
Passing in the handler finalises the MessageHandler construction - you will
not be able to register additional middlewares or hooks after having specified the handler.