Skip to content

[ISSUE #6335]🚀Add producer basic send examples#6336

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

[ISSUE #6335]🚀Add producer basic send examples#6336
mxsm merged 2 commits intomainfrom
feat-6335

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

  • New Features
    • Added a new runnable basic producer example demonstrating synchronous send, send with timeout, send with callback (with and without timeout), and one-way send patterns for RocketMQ producers, with startup/shutdown and logging.
  • Chores
    • Updated project example manifest to register the new example.

@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💥.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 15, 2026

Walkthrough

This PR adds a new RocketMQ producer example demonstrating basic send operations. It registers a new example binary in the Cargo.toml manifest and provides a complete example file showcasing synchronous send, send with timeout, send with callback, and one-way send methods.

Changes

Cohort / File(s) Summary
Manifest Configuration
rocketmq-example/Cargo.toml
Added [[example]] entry for producer-basic-send pointing to examples/producer/basic_send.rs (newline normalized).
Producer Example Implementation
rocketmq-example/examples/producer/basic_send.rs
New async example file adding constants, an annotated main entry, helper functions, and five producer send demos: sync send, send with timeout, send with callback, send with callback+timeout, and one-way send. Includes logging init and producer lifecycle management.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    actor User as "Developer (runs example)"
    rect rgba(100,149,237,0.5)
        participant App as "example::main"
    end
    rect rgba(60,179,113,0.5)
        participant Producer as "MQ Producer"
    end
    rect rgba(255,165,0,0.5)
        participant NameServer as "NameServer/Broker"
    end
    User->>App: run async main()
    App->>Producer: build & start()
    Producer->>NameServer: resolve broker / send message(s)
    NameServer-->>Producer: ack / send result
    Producer-->>App: return SendResult / trigger callback
    App->>Producer: shutdown()
    Producer-->>App: stopped
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested reviewers

  • SpaceXCN
  • TeslaRustor
  • rocketmq-rust-bot

Poem

🐰 In fields of crates I hop and send,

Five little messages I send to a friend.
Sync, timed, callbacks that sing,
One-way hops on a breezy spring.
🥕📬

🚥 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 '[ISSUE #6335]🚀Add producer basic send examples' clearly summarizes the main change: adding basic producer send examples. It references the issue and directly describes the primary change.
Linked Issues check ✅ Passed The PR successfully adds producer basic send examples as required by issue #6335. The new example file demonstrates multiple send methods (synchronous, with timeout, with callback, one-way) meeting the core objective.
Out of Scope Changes check ✅ Passed All changes are directly related to the stated objective. The Cargo.toml modification registers the new example, and the new example file contains only producer send demonstrations with no unrelated code.
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-6335

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: 2

🤖 Fix all issues with AI agents
In `@rocketmq-example/examples/producer/basic_send.rs`:
- Around line 161-168: The call to producer.send_with_callback_timeout is
misformatted and fails CI; reformat the invocation to match the project's
rustfmt style (as done for send_with_callback) by breaking arguments/closure
across lines consistently and aligning the closure arms, then run cargo fmt;
update the call site in basic_send.rs (producer.send_with_callback_timeout) so
the closure and TIMEOUT_MS argument are formatted per rustfmt.
- Around line 133-140: The closure passed into producer.send_with_callback is
formatted in a way that fails cargo fmt; reformat the multi-line closure
arguments and body to follow rustfmt style and then run cargo fmt --all to
update the file, specifically adjusting the call to producer.send_with_callback
and the closure that references SendResult and std::error::Error so the
parameters and match arms are properly indented and wrapped per rustfmt.
🧹 Nitpick comments (1)
rocketmq-example/examples/producer/basic_send.rs (1)

122-144: Consider extracting the duplicated callback closure.

The callback closure is identical in send_with_callback and send_with_callback_timeout. You could extract it into a local function or variable to reduce duplication.

♻️ Example
fn 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 send_callback in both call sites.

Also applies to: 150-172

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/basic_send.rs`:
- Around line 84-87: The log text for the None branch of the synchronous send
path is misleading; update the println calls in the match handling of
producer.send(message).await and producer.send_with_timeout(message, ...).await
to use a neutral message (e.g., "Result: No send result returned" or similar)
instead of "None (async delivery)"; edit the match arms that print the result in
the functions calling producer.send and producer.send_with_timeout so they
reflect that None simply means no result was returned, not async delivery.

Comment on lines +84 to +87
match producer.send(message).await? {
Some(result) => println!(" Result: {:?}", result),
None => println!(" Result: None (async delivery)"),
}
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

Misleading None branch message in synchronous send.

The comment "None (async delivery)" is confusing here since this is the synchronous send method. A None return from producer.send() doesn't imply async delivery. The same issue appears on line 110 in send_with_timeout. Consider a more neutral message like "Result: No send result returned".

Proposed fix
     match producer.send(message).await? {
         Some(result) => println!("   Result: {:?}", result),
-        None => println!("   Result: None (async delivery)"),
+        None => println!("   Result: No send result returned"),
     }

And similarly in send_with_timeout (line 110):

     match producer.send_with_timeout(message, TIMEOUT_MS).await? {
         Some(result) => println!("   Result: {:?}", result),
-        None => println!("   Result: None (async delivery)"),
+        None => println!("   Result: No send result returned"),
     }
📝 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
match producer.send(message).await? {
Some(result) => println!(" Result: {:?}", result),
None => println!(" Result: None (async delivery)"),
}
match producer.send(message).await? {
Some(result) => println!(" Result: {:?}", result),
None => println!(" Result: No send result returned"),
}
🤖 Prompt for AI Agents
In `@rocketmq-example/examples/producer/basic_send.rs` around lines 84 - 87, The
log text for the None branch of the synchronous send path is misleading; update
the println calls in the match handling of producer.send(message).await and
producer.send_with_timeout(message, ...).await to use a neutral message (e.g.,
"Result: No send result returned" or similar) instead of "None (async
delivery)"; edit the match arms that print the result in the functions calling
producer.send and producer.send_with_timeout so they reflect that None simply
means no result was returned, not async delivery.

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 3115e9b into main Feb 15, 2026
10 checks passed
@mxsm mxsm deleted the feat-6335 branch February 15, 2026 13:04
@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 basic send examples

3 participants