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