|
90 | 90 | import com.alibaba.rocketmq.common.protocol.header.filtersrv.RegisterFilterServerResponseHeader;
|
91 | 91 | import com.alibaba.rocketmq.common.protocol.heartbeat.SubscriptionData;
|
92 | 92 | import com.alibaba.rocketmq.common.subscription.SubscriptionGroupConfig;
|
| 93 | +import com.alibaba.rocketmq.remoting.CommandCustomHeader; |
93 | 94 | import com.alibaba.rocketmq.remoting.common.RemotingHelper;
|
94 | 95 | import com.alibaba.rocketmq.remoting.exception.RemotingCommandException;
|
95 | 96 | import com.alibaba.rocketmq.remoting.netty.NettyRequestProcessor;
|
@@ -228,93 +229,67 @@ public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand
|
228 | 229 | }
|
229 | 230 |
|
230 | 231 |
|
231 |
| - private RemotingCommand consumeMessageDirectly(ChannelHandlerContext ctx, RemotingCommand request) |
232 |
| - throws RemotingCommandException { |
| 232 | + private RemotingCommand callConsumer(// |
| 233 | + final int requestCode,// |
| 234 | + final CommandCustomHeader requestHeader, // |
| 235 | + final String consumerGroup,// |
| 236 | + final String clientId) throws RemotingCommandException { |
233 | 237 | final RemotingCommand response = RemotingCommand.createResponseCommand(null);
|
234 |
| - final ConsumeMessageDirectlyResultRequestHeader requestHeader = |
235 |
| - (ConsumeMessageDirectlyResultRequestHeader) request |
236 |
| - .decodeCommandCustomHeader(ConsumeMessageDirectlyResultRequestHeader.class); |
237 |
| - |
238 | 238 | ClientChannelInfo clientChannelInfo =
|
239 |
| - this.brokerController.getConsumerManager().findChannel(requestHeader.getConsumerGroup(), |
240 |
| - requestHeader.getClientId()); |
| 239 | + this.brokerController.getConsumerManager().findChannel(consumerGroup, clientId); |
241 | 240 |
|
242 | 241 | if (null == clientChannelInfo) {
|
243 | 242 | response.setCode(ResponseCode.SYSTEM_ERROR);
|
244 |
| - response.setRemark(String.format("The Consumer <%s> not online", requestHeader.getClientId())); |
| 243 | + response.setRemark(String.format("The Consumer <%s> <%s> not online", consumerGroup, clientId)); |
245 | 244 | return response;
|
246 | 245 | }
|
247 | 246 |
|
248 | 247 | if (clientChannelInfo.getVersion() < MQVersion.Version.V3_1_8_SNAPSHOT.ordinal()) {
|
249 | 248 | response.setCode(ResponseCode.SYSTEM_ERROR);
|
250 | 249 | response.setRemark(String.format(
|
251 | 250 | "The Consumer <%s> Version <%s> too low to finish, please upgrade it to V3_1_8_SNAPSHOT", //
|
252 |
| - requestHeader.getClientId(),// |
| 251 | + clientId,// |
253 | 252 | MQVersion.getVersionDesc(clientChannelInfo.getVersion())));
|
254 | 253 | return response;
|
255 | 254 | }
|
256 | 255 |
|
257 | 256 | try {
|
258 |
| - RemotingCommand newRequest = |
259 |
| - RemotingCommand.createRequestCommand(RequestCode.CONSUME_MESSAGE_DIRECTLY, requestHeader); |
| 257 | + RemotingCommand newRequest = RemotingCommand.createRequestCommand(requestCode, requestHeader); |
260 | 258 | RemotingCommand consumerResponse =
|
261 |
| - this.brokerController.getBroker2Client().getConsumerRunningInfo( |
262 |
| - clientChannelInfo.getChannel(), newRequest); |
| 259 | + this.brokerController.getBroker2Client().callClient(clientChannelInfo.getChannel(), |
| 260 | + newRequest); |
263 | 261 | return consumerResponse;
|
264 | 262 | }
|
265 | 263 | catch (Exception e) {
|
266 | 264 | response.setCode(ResponseCode.SYSTEM_ERROR);
|
267 |
| - response.setRemark(String.format("invoke consumer <%s> Exception: %s", |
268 |
| - requestHeader.getClientId(), RemotingHelper.exceptionSimpleDesc(e))); |
| 265 | + response.setRemark(String.format("invoke consumer <%s> <%s> Exception: %s", consumerGroup, |
| 266 | + clientId, RemotingHelper.exceptionSimpleDesc(e))); |
269 | 267 | return response;
|
270 | 268 | }
|
271 | 269 | }
|
272 | 270 |
|
273 | 271 |
|
| 272 | + private RemotingCommand consumeMessageDirectly(ChannelHandlerContext ctx, RemotingCommand request) |
| 273 | + throws RemotingCommandException { |
| 274 | + final ConsumeMessageDirectlyResultRequestHeader requestHeader = |
| 275 | + (ConsumeMessageDirectlyResultRequestHeader) request |
| 276 | + .decodeCommandCustomHeader(ConsumeMessageDirectlyResultRequestHeader.class); |
| 277 | + return this.callConsumer(RequestCode.CONSUME_MESSAGE_DIRECTLY, requestHeader, |
| 278 | + requestHeader.getConsumerGroup(), requestHeader.getClientId()); |
| 279 | + } |
| 280 | + |
| 281 | + |
274 | 282 | /**
|
275 | 283 | * 调用Consumer,获取Consumer内存数据结构,为监控以及定位问题
|
276 | 284 | */
|
277 | 285 | private RemotingCommand getConsumerRunningInfo(ChannelHandlerContext ctx, RemotingCommand request)
|
278 | 286 | throws RemotingCommandException {
|
279 |
| - final RemotingCommand response = RemotingCommand.createResponseCommand(null); |
280 | 287 | final GetConsumerRunningInfoRequestHeader requestHeader =
|
281 | 288 | (GetConsumerRunningInfoRequestHeader) request
|
282 | 289 | .decodeCommandCustomHeader(GetConsumerRunningInfoRequestHeader.class);
|
283 | 290 |
|
284 |
| - ClientChannelInfo clientChannelInfo = |
285 |
| - this.brokerController.getConsumerManager().findChannel(requestHeader.getConsumerGroup(), |
286 |
| - requestHeader.getClientId()); |
287 |
| - |
288 |
| - if (null == clientChannelInfo) { |
289 |
| - response.setCode(ResponseCode.SYSTEM_ERROR); |
290 |
| - response.setRemark(String.format("The Consumer <%s> not online", requestHeader.getClientId())); |
291 |
| - return response; |
292 |
| - } |
293 |
| - |
294 |
| - if (clientChannelInfo.getVersion() < MQVersion.Version.V3_1_8_SNAPSHOT.ordinal()) { |
295 |
| - response.setCode(ResponseCode.SYSTEM_ERROR); |
296 |
| - response.setRemark(String.format( |
297 |
| - "The Consumer <%s> Version <%s> too low to finish, please upgrade it to V3_1_8_SNAPSHOT", // |
298 |
| - requestHeader.getClientId(),// |
299 |
| - MQVersion.getVersionDesc(clientChannelInfo.getVersion()))); |
300 |
| - return response; |
301 |
| - } |
302 |
| - |
303 |
| - try { |
304 |
| - RemotingCommand newRequest = |
305 |
| - RemotingCommand |
306 |
| - .createRequestCommand(RequestCode.GET_CONSUMER_RUNNING_INFO, requestHeader); |
307 |
| - RemotingCommand consumerResponse = |
308 |
| - this.brokerController.getBroker2Client().getConsumerRunningInfo( |
309 |
| - clientChannelInfo.getChannel(), newRequest); |
310 |
| - return consumerResponse; |
311 |
| - } |
312 |
| - catch (Exception e) { |
313 |
| - response.setCode(ResponseCode.SYSTEM_ERROR); |
314 |
| - response.setRemark(String.format("invoke consumer <%s> Exception: %s", |
315 |
| - requestHeader.getClientId(), RemotingHelper.exceptionSimpleDesc(e))); |
316 |
| - return response; |
317 |
| - } |
| 291 | + return this.callConsumer(RequestCode.GET_CONSUMER_RUNNING_INFO, requestHeader, |
| 292 | + requestHeader.getConsumerGroup(), requestHeader.getClientId()); |
318 | 293 | }
|
319 | 294 |
|
320 | 295 |
|
|
0 commit comments