-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[ISSUE #2554]🚀Fix pop consumer can't start🔥 #2555
Conversation
WalkthroughThe changes update the administration configuration across multiple modules. In the RocketMQ client and tools, the initialization of the Changes
Sequence Diagram(s)sequenceDiagram
participant App as Application
participant Admin as DefaultMQAdminExtImpl
App->>Admin: Call new(rpc_hook, timeout, client_config, admin_ext_group)
Admin-->>App: Return instance with admin_ext_group configured
sequenceDiagram
participant Consumer as PopConsumer
participant Config as ClientConfig
Consumer->>Config: Retrieve mutable config via client_config_mut()
Config-->>Consumer: Provide mutable client configuration
Consumer->>Config: Set namesrv_addr to DEFAULT_NAMESRVADDR (as CheetahString)
Consumer-->>Consumer: Proceed with consumer switch logic
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
🔊@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💥. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🔭 Outside diff range comments (2)
rocketmq-example/examples/consumer/pop_consumer.rs (2)
63-94
:⚠️ Potential issueImprove error handling in switch_pop_consumer function.
The function uses multiple
unwrap()
calls which could lead to runtime panics. Consider proper error handling using the?
operator or explicit error handling.Apply this diff to improve error handling:
async fn switch_pop_consumer() -> Result<()> { let mut mq_admin_ext = DefaultMQAdminExt::new(); mq_admin_ext.client_config_mut().namesrv_addr = Some(CheetahString::from_static_str(DEFAULT_NAMESRVADDR)); - MQAdminExt::start(&mut mq_admin_ext).await.unwrap(); - let broker_datas = - MQAdminExt::examine_topic_route_info(&mq_admin_ext, CheetahString::from_static_str(TOPIC)) - .await - .unwrap(); + MQAdminExt::start(&mut mq_admin_ext).await?; + let broker_datas = MQAdminExt::examine_topic_route_info( + &mq_admin_ext, + CheetahString::from_static_str(TOPIC), + ).await?; for broker_data in broker_datas.broker_datas { let broker_addrs = broker_data .broker_addrs() .values() .cloned() .into_iter() .collect::<HashSet<CheetahString>>(); for broker_addr in broker_addrs { - MQAdminExt::set_message_request_mode( + MQAdminExt::set_message_request_mode( &mq_admin_ext, broker_addr, CheetahString::from_static_str(TOPIC), CheetahString::from_static_str(CONSUMER_GROUP), MessageRequestMode::Pop, 8, 3_000, ) .await - .unwrap(); + ?; } } Ok(()) }
40-61
: 🛠️ Refactor suggestionAdd error handling for consumer startup.
The main function's consumer startup could benefit from proper error handling.
Apply this diff to improve error handling:
#[rocketmq::main] pub async fn main() -> Result<()> { //init logger rocketmq_common::log::init_logger(); - switch_pop_consumer().await?; + if let Err(e) = switch_pop_consumer().await { + eprintln!("Failed to switch pop consumer: {}", e); + return Err(e); + } // create a producer builder with default configuration let builder = DefaultMQPushConsumer::builder(); let mut consumer = builder .consumer_group(CONSUMER_GROUP.to_string()) .name_server_addr(DEFAULT_NAMESRVADDR.to_string()) // disable client side load balance, also is pop consumer .client_rebalance(false) .build(); - consumer.subscribe(TOPIC, "*")?; - consumer.register_message_listener_concurrently(MyMessageListener); - consumer.start().await?; + if let Err(e) = consumer.subscribe(TOPIC, "*") { + eprintln!("Failed to subscribe to topic: {}", e); + return Err(e); + } + consumer.register_message_listener_concurrently(MyMessageListener); + if let Err(e) = consumer.start().await { + eprintln!("Failed to start consumer: {}", e); + return Err(e); + } let _ = wait_for_signal().await; Ok(()) }
🧹 Nitpick comments (1)
rocketmq-example/examples/consumer/pop_consumer.rs (1)
96-109
: Add logging for message processing errors.The message listener should log any errors that occur during message processing.
Apply this diff to improve error handling in the message listener:
impl MessageListenerConcurrently for MyMessageListener { fn consume_message( &self, msgs: &[&MessageExt], _context: &ConsumeConcurrentlyContext, ) -> Result<ConsumeConcurrentlyStatus> { for msg in msgs { - info!("Receive message: {:?}", msg); + match process_message(msg) { + Ok(_) => info!("Successfully processed message: {:?}", msg), + Err(e) => { + error!("Failed to process message: {:?}, error: {}", msg, e); + return Ok(ConsumeConcurrentlyStatus::ReconsumeLater); + } + } } Ok(ConsumeConcurrentlyStatus::ConsumeSuccess) } } fn process_message(msg: &MessageExt) -> Result<()> { info!("Processing message: {:?}", msg); // Add your message processing logic here Ok(()) }
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
rocketmq-client/src/admin/default_mq_admin_ext_impl.rs
(2 hunks)rocketmq-example/examples/consumer/pop_consumer.rs
(1 hunks)rocketmq-tools/src/admin/default_mq_admin_ext.rs
(8 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (9)
- GitHub Check: build (windows-latest, nightly)
- GitHub Check: build (windows-latest, stable)
- GitHub Check: build (macos-latest, nightly)
- GitHub Check: build (macos-latest, stable)
- GitHub Check: test
- GitHub Check: build (ubuntu-latest, nightly)
- GitHub Check: build
- GitHub Check: auto-approve
- GitHub Check: build (ubuntu-latest, stable)
🔇 Additional comments (5)
rocketmq-example/examples/consumer/pop_consumer.rs (1)
65-66
: LGTM! Explicit configuration of namesrv_addr.The addition of explicit namesrv_addr configuration improves the clarity of the connection setup.
rocketmq-client/src/admin/default_mq_admin_ext_impl.rs (2)
96-115
: LGTM! Constructor parameter addition improves configurability.The addition of the
admin_ext_group
parameter to the constructor enhances the configurability of theDefaultMQAdminExtImpl
struct.
85-93
: LGTM! Struct field initialization is consistent.The initialization of the
admin_ext_group
field directly from the constructor parameter maintains consistency.rocketmq-tools/src/admin/default_mq_admin_ext.rs (2)
185-193
: LGTM! Well-designed accessor methods.The addition of inline accessor methods for client configuration follows good encapsulation practices.
62-183
: LGTM! Consistent admin_ext_group initialization.The changes ensure consistent initialization of admin_ext_group across all constructors by using a local variable.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2555 +/- ##
==========================================
- Coverage 28.53% 28.52% -0.01%
==========================================
Files 512 512
Lines 74386 74405 +19
==========================================
Hits 21224 21224
- Misses 53162 53181 +19 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Which Issue(s) This PR Fixes(Closes)
Fixes #2554
Brief Description
How Did You Test This Change?
Summary by CodeRabbit