Skip to content

Commit cfe69a0

Browse files
authored
[ISSUE #1768]📝Add Doc for RebalanceService struct🔥 (#1769)
1 parent e348020 commit cfe69a0

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

rocketmq-client/src/consumer/consumer_impl/re_balance/rebalance_service.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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)]
5079
pub struct RebalanceService {
5180
notify: Arc<Notify>,

0 commit comments

Comments
 (0)