Skip to main content

ConsumeMessageHook

Trait ConsumeMessageHook 

Source
pub trait ConsumeMessageHook: Send + Sync {
    // Required methods
    fn hook_name(&self) -> &'static str;
    fn consume_message_before(&self, context: &mut ConsumeMessageContext<'_>);
    fn consume_message_after(&self, context: &mut ConsumeMessageContext<'_>);
}
Expand description

Hook for message consumption lifecycle events.

Implementations are invoked synchronously before and after each batch of messages is consumed by a push consumer. Multiple hooks may be registered and are executed in registration order.

§Examples

ⓘ
use rocketmq_client::ConsumeMessageContext;
use rocketmq_client::ConsumeMessageHook;

struct LoggingHook;

impl ConsumeMessageHook for LoggingHook {
    fn hook_name(&self) -> &'static str {
        "LoggingHook"
    }

    fn consume_message_before(&self, context: &ConsumeMessageContext) {
        println!("Before consuming {} messages from {}",
                 context.msg_list.len(), context.consumer_group);
    }

    fn consume_message_after(&self, context: &ConsumeMessageContext) {
        println!("After consuming, success: {}", context.success);
    }
}

Required Methods§

Source

fn hook_name(&self) -> &'static str

Returns the unique name of this hook.

Source

fn consume_message_before(&self, context: &mut ConsumeMessageContext<'_>)

Invoked before message consumption begins.

Source

fn consume_message_after(&self, context: &mut ConsumeMessageContext<'_>)

Invoked after message consumption completes.

The context reflects the final consumption status, including whether the messages were consumed successfully.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§