Skip to content

[ISSUE #6618]🚀Add hash-based message queue selector#6619

Merged
rocketmq-rust-bot merged 1 commit intomainfrom
feat-6618
Mar 1, 2026
Merged

[ISSUE #6618]🚀Add hash-based message queue selector#6619
rocketmq-rust-bot merged 1 commit intomainfrom
feat-6618

Conversation

@mxsm
Copy link
Owner

@mxsm mxsm commented Mar 1, 2026

Which Issue(s) This PR Fixes(Closes)

Brief Description

How Did You Test This Change?

Summary by CodeRabbit

Release Notes

  • New Features

    • Added a hash-based message queue selector for efficient queue selection and distribution.
  • Tests

    • Introduced performance benchmarks for queue selector implementations.
    • Added comprehensive unit tests covering queue selection behavior, distribution, and edge cases.

@rocketmq-rust-bot
Copy link
Collaborator

🔊@mxsm 🚀Thanks for your contribution🎉!

💡CodeRabbit(AI) will review your code first🔥!

Note

🚨The code review suggestions from CodeRabbit are to be used as a reference only, and the PR submitter can decide whether to make changes based on their own judgment. Ultimately, the project management personnel will conduct the final code review💥.

@rocketmq-rust-robot rocketmq-rust-robot added the feature🚀 Suggest an idea for this project. label Mar 1, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 1, 2026

Walkthrough

Introduces a new hash-based message queue selector feature to the RocketMQ Rust client. Implements SelectMessageQueueByHash struct with trait support for distributing messages across queues using hash-based routing. Includes comprehensive unit tests and performance benchmarking utilities.

Changes

Cohort / File(s) Summary
Public API Module Declarations
rocketmq-client/src/producer.rs, rocketmq-client/src/producer/queue_selector.rs
Adds public module exports and re-exports for the new queue selection feature, expanding the producer API surface.
Hash-Based Queue Selector Implementation
rocketmq-client/src/producer/queue_selector/select_message_queue_by_hash.rs
Implements SelectMessageQueueByHash struct with MessageQueueSelector trait for zero-cost queue selection via hash-based routing. Includes comprehensive unit tests covering consistency, distribution, edge cases (empty/single queue), and multiple argument types.
Benchmark Utilities
rocketmq-client/benches/select_queue_benchmark.rs
Adds performance benchmarks comparing thread-local cached hasher versus original hasher-based queue selection, using Criterion framework with multiple benchmark scenarios.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A hasher hops through queues so fine,
Distributing messages in a line,
Each argument gets a hash-based ride,
Modulo magic, evenly applied! 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Linked Issues check ❓ Inconclusive Issue #6618 provides no specific requirements or acceptance criteria, only a feature title. The PR implements a hash-based selector matching the issue title, but no detailed objectives exist to validate against. The linked issue lacks detailed requirements. Verify with issue stakeholders that the implementation (hash-based queue selection via DefaultHasher) meets the intended design and performance goals.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: adding a hash-based message queue selector. It directly relates to the implementation across multiple files.
Out of Scope Changes check ✅ Passed All changes directly support hash-based queue selection: benchmark file, public module exports, and the selector implementation. No unrelated modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat-6618

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
rocketmq-client/benches/select_queue_benchmark.rs (1)

54-70: Consider using ::new() for consistency.

Line 55 uses SelectMessageQueueByHash directly while the unit tests use SelectMessageQueueByHash::new(). Both work, but ::new() is more explicit and consistent with the test code.

♻️ Suggested change
 fn bench_select_original(c: &mut Criterion) {
-    let selector = SelectMessageQueueByHash;
+    let selector = SelectMessageQueueByHash::new();
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@rocketmq-client/benches/select_queue_benchmark.rs` around lines 54 - 70,
Replace the direct type value with an explicit constructor to match tests: in
bench_select_original create the selector using SelectMessageQueueByHash::new()
instead of referencing SelectMessageQueueByHash directly; update the variable
initialization for selector where SelectMessageQueueByHash is used so it calls
the new() method.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@rocketmq-client/benches/select_queue_benchmark.rs`:
- Around line 1-13: The source file is missing the required copyright header;
add the repository-standard header containing "Copyright 2023" at the very top
of the Rust file (above the first use statements such as use
criterion::criterion_group and use
rocketmq_client_rust::producer::message_queue_selector::MessageQueueSelector) so
every .rs file includes the mandated license header.

---

Nitpick comments:
In `@rocketmq-client/benches/select_queue_benchmark.rs`:
- Around line 54-70: Replace the direct type value with an explicit constructor
to match tests: in bench_select_original create the selector using
SelectMessageQueueByHash::new() instead of referencing SelectMessageQueueByHash
directly; update the variable initialization for selector where
SelectMessageQueueByHash is used so it calls the new() method.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between da0bba5 and 251d2e9.

📒 Files selected for processing (4)
  • rocketmq-client/benches/select_queue_benchmark.rs
  • rocketmq-client/src/producer.rs
  • rocketmq-client/src/producer/queue_selector.rs
  • rocketmq-client/src/producer/queue_selector/select_message_queue_by_hash.rs

Comment on lines +1 to +13
use criterion::criterion_group;
use criterion::criterion_main;
use criterion::Criterion;
use rocketmq_client_rust::producer::message_queue_selector::MessageQueueSelector;
use rocketmq_client_rust::producer::queue_selector::SelectMessageQueueByHash;
use rocketmq_common::common::message::message_queue::MessageQueue;
use rocketmq_common::common::message::message_single::Message;
use std::cell::RefCell;
use std::collections::hash_map::DefaultHasher;
use std::hash::Hash;
use std::hash::Hasher;
use std::hint::black_box;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Add the copyright header.

This file is missing the required copyright header. Per repository convention, all Rust source files must include the "Copyright 2023" header.

📝 Proposed fix
+// Copyright 2023 The RocketMQ Rust Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
 use criterion::criterion_group;

Based on learnings: "In Rust source files (*.rs) across the rocketmq-rust repository, enforce using 'Copyright 2023' as the year in the header."

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
use criterion::criterion_group;
use criterion::criterion_main;
use criterion::Criterion;
use rocketmq_client_rust::producer::message_queue_selector::MessageQueueSelector;
use rocketmq_client_rust::producer::queue_selector::SelectMessageQueueByHash;
use rocketmq_common::common::message::message_queue::MessageQueue;
use rocketmq_common::common::message::message_single::Message;
use std::cell::RefCell;
use std::collections::hash_map::DefaultHasher;
use std::hash::Hash;
use std::hash::Hasher;
use std::hint::black_box;
// Copyright 2023 The RocketMQ Rust Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use criterion::criterion_group;
use criterion::criterion_main;
use criterion::Criterion;
use rocketmq_client_rust::producer::message_queue_selector::MessageQueueSelector;
use rocketmq_client_rust::producer::queue_selector::SelectMessageQueueByHash;
use rocketmq_common::common::message::message_queue::MessageQueue;
use rocketmq_common::common::message::message_single::Message;
use std::cell::RefCell;
use std::collections::hash_map::DefaultHasher;
use std::hash::Hash;
use std::hash::Hasher;
use std::hint::black_box;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@rocketmq-client/benches/select_queue_benchmark.rs` around lines 1 - 13, The
source file is missing the required copyright header; add the
repository-standard header containing "Copyright 2023" at the very top of the
Rust file (above the first use statements such as use criterion::criterion_group
and use
rocketmq_client_rust::producer::message_queue_selector::MessageQueueSelector) so
every .rs file includes the mandated license header.

@codecov
Copy link

codecov bot commented Mar 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 41.40%. Comparing base (da0bba5) to head (251d2e9).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6619      +/-   ##
==========================================
+ Coverage   41.36%   41.40%   +0.03%     
==========================================
  Files         964      965       +1     
  Lines      135273   135354      +81     
==========================================
+ Hits        55956    56038      +82     
+ Misses      79317    79316       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Collaborator

@rocketmq-rust-bot rocketmq-rust-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - All CI checks passed ✅

@rocketmq-rust-bot rocketmq-rust-bot merged commit 73e06e4 into main Mar 1, 2026
20 checks passed
@rocketmq-rust-bot rocketmq-rust-bot added approved PR has approved and removed ready to review waiting-review waiting review this PR labels Mar 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI review first Ai review pr first approved PR has approved auto merge feature🚀 Suggest an idea for this project.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature🚀] Add hash-based message queue selector

3 participants