Skip to content

[ISSUE #6321]🚀Add producer_simple example for RocketMQ#6322

Merged
mxsm merged 1 commit intomainfrom
feat-6321
Feb 14, 2026
Merged

[ISSUE #6321]🚀Add producer_simple example for RocketMQ#6322
mxsm merged 1 commit intomainfrom
feat-6321

Conversation

@mxsm
Copy link
Owner

@mxsm mxsm commented Feb 14, 2026

Which Issue(s) This PR Fixes(Closes)

Brief Description

How Did You Test This Change?

Summary by CodeRabbit

  • New Features

    • Added a producer example demonstrating message sending with custom configuration, topics, and message tags
  • Chores

    • Restored example build targets in project configuration to expand available reference implementations

@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 14, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 14, 2026

Walkthrough

The PR restores and expands example targets in Cargo.toml, adding pop-consumer and producer-simple examples. It introduces a new producer example demonstrating basic message sending with RocketMQ's DefaultMQProducer, including initialization, configuration, and a message send loop.

Changes

Cohort / File(s) Summary
Example Configuration
rocketmq-example/Cargo.toml
Restores and expands example targets by removing deprecated entry and adding pop-consumer and producer-simple example definitions with their respective paths.
Producer Example Implementation
rocketmq-example/examples/producer/producer_simple.rs
New example demonstrating basic message production workflow: defines configuration constants, initializes DefaultMQProducer using builder pattern, sends 10 messages in a loop, and gracefully shuts down the producer.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A producer takes flight with messages bright,
Through RocketMQ's channels, they soar to great height,
With builder patterns and loops oh so fine,
Example code shows us a wonderful design! 🚀

🚥 Pre-merge checks | ✅ 5 | ❌ 1
❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Linked Issues check ❓ Inconclusive The linked issue #6321 contains no specific objectives, requirements, or acceptance criteria, making compliance assessment impossible. Add detailed requirements and acceptance criteria to issue #6321, such as expected functionality, configuration parameters, and usage patterns for the producer_simple example.
✅ Passed checks (5 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 producer_simple example for RocketMQ, which is directly reflected in the code changes.
Out of Scope Changes check ✅ Passed All changes are in-scope: Cargo.toml modifications enable example targets, and the new producer_simple.rs file directly implements the stated objective.
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-6321

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/producer_simple.rs`:
- Line 21: The constant MESSAGE_COUNT is unused while the send loop is hardcoded
to 10; update the for loop that currently iterates 0..10 to use MESSAGE_COUNT
(e.g., for i in 0..MESSAGE_COUNT) so the constant controls the number of
messages, or remove MESSAGE_COUNT if you prefer a literal—ensure the loop bound
and MESSAGE_COUNT are the same type (usize) and update any related comments or
tests accordingly.
🧹 Nitpick comments (1)
rocketmq-example/examples/producer/producer_simple.rs (1)

38-49: Producer shutdown is skipped if send fails.

If producer.send(message).await? returns an error, the early ? return bypasses producer.shutdown() on line 49. Consider ensuring shutdown runs regardless of send errors, which is also better practice to demonstrate in an example.

Proposed fix — ensure shutdown on all paths
-    for _ in 0..10 {
+    let result: RocketMQResult<()> = async {
+      for _ in 0..MESSAGE_COUNT {
         let message = Message::builder()
             .topic(TOPIC)
             .tags(TAG)
             .body("Hello RocketMQ")
             .build()?;
         let send_result = producer.send(message).await?;
         println!("send result: {:?}", send_result);
-    }
-    producer.shutdown().await;
-    Ok(())
+      }
+      Ok(())
+    }.await;
+    producer.shutdown().await;
+    result

use rocketmq_error::RocketMQResult;
use rocketmq_rust::rocketmq;

pub const MESSAGE_COUNT: usize = 1;
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

MESSAGE_COUNT is defined but never used; loop count is hardcoded.

MESSAGE_COUNT is set to 1 but the loop on line 40 hardcodes 10. Either use the constant in the loop or remove it. The values also disagree (1 vs 10).

Proposed fix
-pub const MESSAGE_COUNT: usize = 1;
+pub const MESSAGE_COUNT: usize = 10;
-    for _ in 0..10 {
+    for _ in 0..MESSAGE_COUNT {

Also applies to: 40-40

🤖 Prompt for AI Agents
In `@rocketmq-example/examples/producer/producer_simple.rs` at line 21, The
constant MESSAGE_COUNT is unused while the send loop is hardcoded to 10; update
the for loop that currently iterates 0..10 to use MESSAGE_COUNT (e.g., for i in
0..MESSAGE_COUNT) so the constant controls the number of messages, or remove
MESSAGE_COUNT if you prefer a literal—ensure the loop bound and MESSAGE_COUNT
are the same type (usize) and update any related comments or tests accordingly.

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 505c690 into main Feb 14, 2026
17 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 Feb 14, 2026
@mxsm mxsm deleted the feat-6321 branch February 22, 2026 05:26
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_simple example for RocketMQ

3 participants