@@ -46,6 +46,35 @@ static MIN_INTERVAL: Lazy<Duration> = Lazy::new(|| {
4646 } )
4747} ) ;
4848
49+ ///`RebalanceService` is a crucial struct in Apache RocketMQ-Rust, responsible for coordinating
50+ /// load balancing among the consumers of a message queue. Its primary function is to ensure that
51+ /// consumer instances can reasonably distribute message queues among multiple consumers, achieving
52+ /// efficient message processing and balanced load. Specifically, the role of `RebalanceService`
53+ /// includes the following aspects:
54+ ///
55+ /// 1. **Consumer Load Balancing** When consumers in a consumer group start, stop, or fail,
56+ /// `RebalanceService` dynamically adjusts the message queue distribution between consumers to
57+ /// ensure each consumer processes a reasonable number of queues, avoiding situations where some
58+ /// consumers are overburdened or underutilized.
59+ /// 2. **Queue Allocation and Revocation** `RebalanceService` triggers reallocation of consumer
60+ /// queues periodically or when certain events occur. It decides which queues should be processed
61+ /// by which consumers based on the number of consumers, the state of consumer instances, and the
62+ /// number of message queues.
63+ /// 3. **Consumer Failure Recovery** If a consumer instance fails or goes offline,
64+ /// `RebalanceService` triggers a rebalancing operation, redistributing the queues it was
65+ /// responsible for to other online consumers, ensuring that messages are not lost and the load
66+ /// is evenly distributed.
67+ /// 4. **Consumer Rejoining** When a new consumer joins the consumer group, `RebalanceService`
68+ /// initiates a rebalancing process, adding the new consumer to the queue allocation and
69+ /// adjusting the queues for each consumer to ensure the load is balanced across the entire
70+ /// consumer group.
71+ /// 5. **Listening for Queue State Changes** `RebalanceService` listens for changes in the state of
72+ /// consumers and queues in RocketMQ, adjusting queue allocations based on these changes.
73+ ///
74+ /// This service is integral to ensuring that the consumers in a RocketMQ cluster maintain high
75+ /// availability, optimal resource utilization, and fault tolerance while processing messages
76+ /// efficiently.
77+
4978#[ derive( Clone ) ]
5079pub struct RebalanceService {
5180 notify : Arc < Notify > ,
0 commit comments