MessageHandlerBuilder

Struct MessageHandlerBuilder 

Source
pub struct MessageHandlerBuilder<Context, Error>
where Context: Send + Sync + 'static, Error: Send + Sync + 'static,
{ /* 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>
where Context: Send + Sync + 'static, Error: Send + Sync + 'static,

Source

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.

Source

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.

Source

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.

Source

pub fn with_dyn_processing_middleware( self, middleware: Arc<dyn ProcessingMiddleware<Context, Error>>, ) -> Self

Append dynamic processing middleware logic, see MessageHandlerBuilder::with_processing_middleware.

Source

pub fn with_processing_middlewares<I>(self, middlewares: I) -> Self
where I: IntoIterator<Item = Arc<dyn ProcessingMiddleware<Context, Error>>>,

Append multiple dynamic processing middlewares, see MessageHandlerBuilder::with_processing_middleware.

Source

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.

Source

pub fn with_dyn_telemetry_middleware( self, middleware: Arc<dyn TelemetryMiddleware<Context, Error>>, ) -> Self

Append dynamic telemetry middleware logic, see MessageHandlerBuilder::with_telemetry_middleware.

Source

pub fn with_telemetry_middlewares<I>(self, middlewares: I) -> Self
where I: IntoIterator<Item = Arc<dyn TelemetryMiddleware<Context, Error>>>,

Append multiple dynamic telemetry middlewares, see MessageHandlerBuilder::with_telemetry_middleware.

Source

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.

Source

pub fn with_pre_start_hooks<I>(self, hooks: I) -> Self
where I: IntoIterator<Item = Arc<dyn ConsumerPreStartHook>>,

Append multiple pre-start hooks, see MessageHandlerBuilder::with_pre_start_hook.

Source

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.

Source

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.

Source

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);
Source

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.

Source

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.

Auto Trait Implementations§

§

impl<Context, Error> Freeze for MessageHandlerBuilder<Context, Error>

§

impl<Context, Error> !RefUnwindSafe for MessageHandlerBuilder<Context, Error>

§

impl<Context, Error> Send for MessageHandlerBuilder<Context, Error>

§

impl<Context, Error> Sync for MessageHandlerBuilder<Context, Error>

§

impl<Context, Error> Unpin for MessageHandlerBuilder<Context, Error>

§

impl<Context, Error> !UnwindSafe for MessageHandlerBuilder<Context, Error>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more