Skip to main content

rocketmq_client_rust/consumer/
allocate_message_queue_strategy.rs

1// Copyright 2023 The RocketMQ Rust Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use cheetah_string::CheetahString;
16use rocketmq_common::common::message::message_queue::MessageQueue;
17
18/// Trait for allocating message queues to consumers in a consumer group.
19/// This trait is implemented by different strategies for message queue allocation.
20pub trait AllocateMessageQueueStrategy: Send + Sync {
21    /// Allocates message queues to a consumer in a consumer group.
22    ///
23    /// # Arguments
24    ///
25    /// * `consumer_group` - The name of the consumer group.
26    /// * `current_cid` - The ID of the current consumer.
27    /// * `mq_all` - A slice of all available message queues.
28    /// * `cid_all` - A slice of all consumer IDs in the consumer group.
29    ///
30    /// # Returns
31    ///
32    /// A `Result` containing a vector of allocated message queues or an error.
33    fn allocate(
34        &self,
35        consumer_group: &CheetahString,
36        current_cid: &CheetahString,
37        mq_all: &[MessageQueue],
38        cid_all: &[CheetahString],
39    ) -> rocketmq_error::RocketMQResult<Vec<MessageQueue>>;
40
41    /// Returns the name of the allocation strategy.
42    ///
43    /// # Returns
44    ///
45    /// A static string slice representing the name of the strategy.
46    fn get_name(&self) -> &'static str;
47}