-
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 #1106]Fix When topic not create the client can not consume #1108
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -21,19 +21,26 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
use crate::base::client_config::ClientConfig; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
use crate::error::MQClientError::MQClientErr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
use crate::factory::mq_client_instance; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
use crate::factory::mq_client_instance::MQClientInstance; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
use crate::implementation::mq_client_api_impl::MQClientAPIImpl; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
use crate::Result; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pub struct MQAdminImpl { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
timeout_millis: u64, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
client: Option<ArcRefCellWrapper<MQClientInstance>>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
impl MQAdminImpl { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pub fn new() -> Self { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
MQAdminImpl { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
timeout_millis: 60000, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
client: None, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pub fn set_client(&mut self, client: ArcRefCellWrapper<MQClientInstance>) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.client = Some(client); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
impl MQAdminImpl { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -93,6 +100,30 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pub async fn max_offset(&mut self, mq: &MessageQueue) -> Result<i64> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let client = self.client.as_mut().expect("client is None"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let broker_name = client.get_broker_name_from_message_queue(mq).await; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let mut broker_addr = client | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.find_broker_address_in_publish(broker_name.as_str()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.await; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if broker_addr.is_none() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
client | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.update_topic_route_info_from_name_server_topic(mq.get_topic()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.await; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let broker_name = client.get_broker_name_from_message_queue(mq).await; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
broker_addr = client | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.find_broker_address_in_publish(broker_name.as_str()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.await; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if let Some(ref broker_addr) = broker_addr { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let offset = client | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.mq_client_api_impl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.as_mut() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.expect("mq_client_api_impl is None") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.get_max_offset(broker_addr, mq, self.timeout_millis) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.await?; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return Ok(offset); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+103
to
+126
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Handle potential Using Apply the following changes to handle - let client = self.client.as_mut().expect("client is None");
+ let client = match self.client.as_mut() {
+ Some(client) => client,
+ None => {
+ return Err(MQClientErr(
+ -1,
+ "MQClientInstance is not initialized".to_string(),
+ ));
+ }
+ };
...
- .as_mut()
- .expect("mq_client_api_impl is None")
+ .as_mut().ok_or_else(|| MQClientErr(
+ -1,
+ "MQClientAPIImpl is not initialized".to_string(),
+ ))?
...
- unimplemented!("max_offset")
+ Err(MQClientErr(
+ -1,
+ "Failed to retrieve broker address; cannot compute max offset".to_string(),
+ )) 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
unimplemented!("max_offset") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pub async fn search_offset(&mut self, mq: &MessageQueue, timestamp: u64) -> Result<i64> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -47,6 +47,8 @@ | |||||||||||||||||||||||||
use rocketmq_remoting::protocol::header::consumer_send_msg_back_request_header::ConsumerSendMsgBackRequestHeader; | ||||||||||||||||||||||||||
use rocketmq_remoting::protocol::header::end_transaction_request_header::EndTransactionRequestHeader; | ||||||||||||||||||||||||||
use rocketmq_remoting::protocol::header::get_consumer_listby_group_request_header::GetConsumerListByGroupRequestHeader; | ||||||||||||||||||||||||||
use rocketmq_remoting::protocol::header::get_max_offset_request_header::GetMaxOffsetRequestHeader; | ||||||||||||||||||||||||||
use rocketmq_remoting::protocol::header::get_max_offset_response_header::GetMaxOffsetResponseHeader; | ||||||||||||||||||||||||||
use rocketmq_remoting::protocol::header::heartbeat_request_header::HeartbeatRequestHeader; | ||||||||||||||||||||||||||
use rocketmq_remoting::protocol::header::lock_batch_mq_request_header::LockBatchMqRequestHeader; | ||||||||||||||||||||||||||
use rocketmq_remoting::protocol::header::message_operation_header::send_message_request_header::SendMessageRequestHeader; | ||||||||||||||||||||||||||
|
@@ -68,6 +70,7 @@ | |||||||||||||||||||||||||
use rocketmq_remoting::protocol::RemotingSerializable; | ||||||||||||||||||||||||||
use rocketmq_remoting::remoting::RemotingService; | ||||||||||||||||||||||||||
use rocketmq_remoting::rpc::rpc_request_header::RpcRequestHeader; | ||||||||||||||||||||||||||
use rocketmq_remoting::rpc::topic_request_header::TopicRequestHeader; | ||||||||||||||||||||||||||
use rocketmq_remoting::runtime::config::client_config::TokioClientConfig; | ||||||||||||||||||||||||||
use rocketmq_remoting::runtime::RPCHook; | ||||||||||||||||||||||||||
use tracing::error; | ||||||||||||||||||||||||||
|
@@ -1147,4 +1150,50 @@ | |||||||||||||||||||||||||
.await; | ||||||||||||||||||||||||||
Ok(()) | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
pub async fn get_max_offset( | ||||||||||||||||||||||||||
&mut self, | ||||||||||||||||||||||||||
addr: &str, | ||||||||||||||||||||||||||
message_queue: &MessageQueue, | ||||||||||||||||||||||||||
timeout_millis: u64, | ||||||||||||||||||||||||||
) -> Result<i64> { | ||||||||||||||||||||||||||
let request_header = GetMaxOffsetRequestHeader { | ||||||||||||||||||||||||||
topic: message_queue.get_topic().to_string(), | ||||||||||||||||||||||||||
queue_id: message_queue.get_queue_id(), | ||||||||||||||||||||||||||
committed: false, | ||||||||||||||||||||||||||
topic_request_header: Some(TopicRequestHeader { | ||||||||||||||||||||||||||
rpc_request_header: Some(RpcRequestHeader { | ||||||||||||||||||||||||||
broker_name: Some(message_queue.get_broker_name().to_string()), | ||||||||||||||||||||||||||
..Default::default() | ||||||||||||||||||||||||||
}), | ||||||||||||||||||||||||||
lo: None, | ||||||||||||||||||||||||||
}), | ||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
let request = | ||||||||||||||||||||||||||
RemotingCommand::create_request_command(RequestCode::GetMaxOffset, request_header); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
let response = self | ||||||||||||||||||||||||||
.remoting_client | ||||||||||||||||||||||||||
.invoke_async( | ||||||||||||||||||||||||||
Some(mix_all::broker_vip_channel( | ||||||||||||||||||||||||||
self.client_config.vip_channel_enabled, | ||||||||||||||||||||||||||
addr, | ||||||||||||||||||||||||||
)), | ||||||||||||||||||||||||||
request, | ||||||||||||||||||||||||||
timeout_millis, | ||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||
.await?; | ||||||||||||||||||||||||||
if ResponseCode::from(response.code()) == ResponseCode::Success { | ||||||||||||||||||||||||||
let response_header = response | ||||||||||||||||||||||||||
.decode_command_custom_header::<GetMaxOffsetResponseHeader>() | ||||||||||||||||||||||||||
.expect("decode error"); | ||||||||||||||||||||||||||
return Ok(response_header.offset); | ||||||||||||||||||||||||||
Comment on lines
+1188
to
+1191
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace expect() with proper error handling. Using - let response_header = response
- .decode_command_custom_header::<GetMaxOffsetResponseHeader>()
- .expect("decode error");
- return Ok(response_header.offset);
+ let response_header = response
+ .decode_command_custom_header::<GetMaxOffsetResponseHeader>()
+ .map_err(|e| MQBrokerError(
+ response.code(),
+ format!("Failed to decode response header: {}", e),
+ addr.to_string(),
+ ))?;
+ return Ok(response_header.offset); 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
Err(MQBrokerError( | ||||||||||||||||||||||||||
response.code(), | ||||||||||||||||||||||||||
response.remark().map_or("".to_string(), |s| s.to_string()), | ||||||||||||||||||||||||||
addr.to_string(), | ||||||||||||||||||||||||||
)) | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} |
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.
Don't disable logger initialization in examples.
Commenting out the logger initialization reduces visibility into potential issues, especially for users trying to debug topic-related problems. Examples should demonstrate best practices including proper logging setup.
📝 Committable suggestion