Skip to content

[ISSUE #6337]🚀Add producer batch send examples#6338

Merged
mxsm merged 2 commits intomainfrom
feat-6337
Feb 15, 2026
Merged

[ISSUE #6337]🚀Add producer batch send examples#6338
mxsm merged 2 commits intomainfrom
feat-6337

Conversation

@mxsm
Copy link
Owner

@mxsm mxsm commented Feb 15, 2026

Which Issue(s) This PR Fixes(Closes)

Brief Description

How Did You Test This Change?

Summary by CodeRabbit

  • Documentation
    • Added a comprehensive batch-send example demonstrating eight batch-sending patterns for the RocketMQ producer (basic, timeout variants, specific-queue targeting, and callback handling).
    • Registered the new example so it appears alongside existing project examples for easy discovery and usage.

@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 Feb 15, 2026
@rocketmq-rust-bot rocketmq-rust-bot added the waiting-review waiting review this PR label Feb 15, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 15, 2026

Walkthrough

Adds a new producer batch-send example: a Cargo.toml example entry plus a new Rust example implementing eight batch-send scenarios (variations of timeout, queue targeting, and callbacks).

Changes

Cohort / File(s) Summary
Configuration
rocketmq-example/Cargo.toml
Adds a [[example]] entry named producer-batch-send pointing to examples/producer/batch_send.rs.
Producer example
rocketmq-example/examples/producer/batch_send.rs
New example file exposing constants (PRODUCER_GROUP, DEFAULT_NAMESRVADDR, TOPIC, TAG, TIMEOUT_MS) and pub async fn main(), demonstrating eight batch-send scenarios: basic, timeout, specific-queue, queue+timeout, callback variants, and shutdown flow.

Sequence Diagram(s)

sequenceDiagram
    participant Example
    participant Producer
    participant NameServer
    participant Broker

    Example->>Producer: build & start producer
    Producer->>NameServer: fetch topic routes / queues
    NameServer-->>Producer: return queues
    Example->>Producer: invoke batch_send / batch_send_with_callback (with optional queue/timeout)
    Producer->>Broker: send batch request
    Broker-->>Producer: send response / ack
    Producer-->>Example: return result or invoke callback
    Example->>Producer: shutdown
    Producer-->>Broker: cleanup connections
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • TeslaRustor
  • SpaceXCN
  • rocketmq-rust-bot

Poem

🐰 In burrows deep I nibble code,

Eight batches launched along the road,
Queues and callbacks, tidy and neat,
Messages hop to every seat,
A rabbit cheers — producer complete! 🎉

🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 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 producer batch send examples, which matches the file additions and Cargo.toml entry.
Linked Issues check ✅ Passed The PR adds producer batch send examples with eight scenarios as intended by issue #6337, fulfilling the feature requirement.
Out of Scope Changes check ✅ Passed All changes are directly related to adding producer batch send examples; no unrelated modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat-6337

No actionable comments were generated in the recent review. 🎉


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

🤖 Fix all issues with AI agents
In `@rocketmq-example/examples/producer/batch_send.rs`:
- Line 159: The CI fails due to rustfmt violations in the producer example; run
`cargo fmt --all` and reformat the multi-line function signature
`batch_send_to_queue` and its call sites so they comply with rustfmt,
specifically reflow the `send_batch_to_queue_with_timeout` and
`send_batch_with_callback` invocations (and other multi-line calls around those
locations) to use the standard Rust multiline call formatting; ensure
`DefaultMQProducer` usage and argument lists are line-wrapped consistently so
`cargo fmt` passes.
🧹 Nitpick comments (2)
rocketmq-example/examples/producer/batch_send.rs (2)

232-239: Consider extracting the duplicated callback closure.

The identical callback closure is repeated four times. For an example file, this is acceptable for readability, but you could reduce duplication with a small helper function.

♻️ Optional: extract shared callback
+fn batch_send_callback(result: Option<&SendResult>, error: Option<&dyn std::error::Error>) {
+    match (result, error) {
+        (Some(r), None) => println!("   Callback: Success - {:?}", r),
+        (None, Some(e)) => println!("   Callback: Error - {}", e),
+        _ => println!("   Callback: Unknown state"),
+    }
+}

Then use batch_send_callback in place of each inline closure.

Also applies to: 266-273, 300-307, 334-341


54-56: Silent skip when no queues are available.

If fetch_publish_message_queues returns an empty list, scenarios 3, 4, 7, and 8 are silently skipped with no indication to the user. Consider printing a warning so the user understands why those examples didn't run.

💡 Suggested improvement
     let queues = producer.fetch_publish_message_queues(TOPIC).await?;
     let target_queue = queues.first().cloned();
+    if target_queue.is_none() {
+        println!("   ⚠ No queues available for topic '{}', queue-specific examples will be skipped.", TOPIC);
+    }

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 ✅

@mxsm mxsm merged commit 840dba6 into main Feb 15, 2026
9 checks passed
@mxsm mxsm deleted the feat-6337 branch February 15, 2026 13:25
@rocketmq-rust-bot rocketmq-rust-bot added approved PR has approved and removed ready to review waiting-review waiting review this PR labels Feb 15, 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 producer batch send examples

3 participants