@@ -35,7 +35,8 @@ use rocketmq_remoting::{
35
35
} ,
36
36
protocol:: {
37
37
header:: message_operation_header:: {
38
- send_message_request_header:: SendMessageRequestHeader , TopicRequestHeaderTrait ,
38
+ send_message_request_header:: SendMessageRequestHeader ,
39
+ send_message_response_header:: SendMessageResponseHeader , TopicRequestHeaderTrait ,
39
40
} ,
40
41
remoting_command:: RemotingCommand ,
41
42
NamespaceUtil ,
@@ -49,7 +50,7 @@ use tracing::{info, warn};
49
50
50
51
use self :: client_manage_processor:: ClientManageProcessor ;
51
52
use crate :: {
52
- mqtrace:: send_message_context:: SendMessageContext ,
53
+ mqtrace:: { send_message_context:: SendMessageContext , send_message_hook :: SendMessageHook } ,
53
54
processor:: {
54
55
admin_broker_processor:: AdminBrokerProcessor , send_message_processor:: SendMessageProcessor ,
55
56
} ,
76
77
pub ( crate ) admin_broker_processor : AdminBrokerProcessor ,
77
78
pub ( crate ) client_manage_processor : ClientManageProcessor ,
78
79
}
79
-
80
80
impl < MS : Clone > Clone for BrokerRequestProcessor < MS > {
81
81
fn clone ( & self ) -> Self {
82
82
Self {
@@ -120,9 +120,38 @@ impl<MS: MessageStore + Send + Sync + 'static> RequestProcessor for BrokerReques
120
120
pub ( crate ) struct SendMessageProcessorInner {
121
121
pub ( crate ) broker_config : Arc < BrokerConfig > ,
122
122
pub ( crate ) topic_config_manager : TopicConfigManager ,
123
+ pub ( crate ) send_message_hook_vec : Arc < parking_lot:: RwLock < Vec < Box < dyn SendMessageHook > > > > ,
123
124
}
124
125
125
126
impl SendMessageProcessorInner {
127
+ pub ( crate ) fn execute_send_message_hook_before ( & self , context : & SendMessageContext ) {
128
+ for hook in self . send_message_hook_vec . read ( ) . iter ( ) {
129
+ hook. send_message_before ( context) ;
130
+ }
131
+ }
132
+
133
+ pub ( crate ) fn execute_send_message_hook_after (
134
+ & self ,
135
+ response : Option < & mut RemotingCommand > ,
136
+ context : & mut SendMessageContext ,
137
+ ) {
138
+ for hook in self . send_message_hook_vec . read ( ) . iter ( ) {
139
+ if let Some ( ref response) = response {
140
+ if let Some ( ref header) =
141
+ response. decode_command_custom_header :: < SendMessageResponseHeader > ( )
142
+ {
143
+ context. msg_id = header. msg_id ( ) . to_string ( ) ;
144
+ context. queue_id = Some ( header. queue_id ( ) ) ;
145
+ context. queue_offset = Some ( header. queue_offset ( ) ) ;
146
+ context. code = response. code ( ) ;
147
+ context. error_msg = response. remark ( ) . unwrap_or ( & "" . to_string ( ) ) . to_string ( ) ;
148
+ }
149
+ }
150
+
151
+ hook. send_message_after ( context) ;
152
+ }
153
+ }
154
+
126
155
pub ( crate ) fn consumer_send_msg_back (
127
156
& self ,
128
157
_ctx : & ConnectionHandlerContext ,
@@ -230,6 +259,7 @@ impl SendMessageProcessorInner {
230
259
"Sending message to topic[{}] is forbidden." ,
231
260
request_header. topic. as_str( )
232
261
) ) ) ;
262
+ return ;
233
263
}
234
264
let mut topic_config = self
235
265
. topic_config_manager
0 commit comments