Skip to main content

MessageQueueListener

Trait MessageQueueListener 

Source
pub trait MessageQueueListener: Send + Sync {
    // Required method
    fn message_queue_changed(
        &self,
        topic: &str,
        mq_all: &HashSet<MessageQueue>,
        mq_assigned: &HashSet<MessageQueue>,
    );
}
Expand description

A listener that is notified when message queue allocation changes during consumer rebalancing.

This trait is used to track changes in the message queues assigned to a consumer instance. It is particularly useful for monitoring and debugging purposes, allowing applications to react to rebalancing events in real-time.

§Thread Safety

Implementations must be thread-safe (Send + Sync) as they may be called from multiple threads.

§Examples

ⓘ
use std::collections::HashSet;
use rocketmq_model::common::message::message_queue::MessageQueue;
use crate::consumer::message_queue_listener::MessageQueueListener;

struct MyQueueListener;

impl MessageQueueListener for MyQueueListener {
    fn message_queue_changed(
        &self,
        topic: &str,
        mq_all: &HashSet<MessageQueue>,
        mq_assigned: &HashSet<MessageQueue>,
    ) {
        println!("Topic: {}", topic);
        println!("All queues: {:?}", mq_all.len());
        println!("Assigned queues: {:?}", mq_assigned.len());
    }
}

Required Methods§

Source

fn message_queue_changed( &self, topic: &str, mq_all: &HashSet<MessageQueue>, mq_assigned: &HashSet<MessageQueue>, )

Called when the message queue allocation for a topic has changed.

This method is invoked during consumer rebalancing when the set of message queues assigned to this consumer instance changes.

§Parameters
  • topic - The topic name for which the queue allocation has changed.
  • mq_all - All message queues available for this topic across all consumers.
  • mq_assigned - The subset of message queues assigned to this consumer instance after rebalancing.
§Notes

This method should execute quickly and avoid blocking operations, as it is called during the rebalancing process.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§