com.alibaba.rocketmq.broker.mqtrace.SendMessageContext Java Examples
The following examples show how to use
com.alibaba.rocketmq.broker.mqtrace.SendMessageContext.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractSendMessageProcessor.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 6 votes |
public void executeSendMessageHookBefore(final ChannelHandlerContext ctx, final RemotingCommand request, SendMessageContext context) { if (hasSendMessageHook()) { for (SendMessageHook hook : this.sendMessageHookList) { try { final SendMessageRequestHeader requestHeader = (SendMessageRequestHeader) request .decodeCommandCustomHeader(SendMessageRequestHeader.class); context.setProducerGroup(requestHeader.getProducerGroup()); context.setTopic(requestHeader.getTopic()); context.setBodyLength(request.getBody().length); context.setMsgProps(requestHeader.getProperties()); context.setBornHost(RemotingHelper.parseChannelRemoteAddr(ctx.channel())); context.setBrokerAddr(this.brokerController.getBrokerAddr()); context.setQueueId(requestHeader.getQueueId()); hook.sendMessageBefore(context); requestHeader.setProperties(context.getMsgProps()); } catch (Throwable e) { } } } }
Example #2
Source File: AbstractSendMessageProcessor.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 6 votes |
public void executeSendMessageHookAfter(final RemotingCommand response, final SendMessageContext context) { if (hasSendMessageHook()) { for (SendMessageHook hook : this.sendMessageHookList) { try { if (response != null) { final SendMessageResponseHeader responseHeader = (SendMessageResponseHeader) response.readCustomHeader(); context.setMsgId(responseHeader.getMsgId()); context.setQueueId(responseHeader.getQueueId()); context.setQueueOffset(responseHeader.getQueueOffset()); context.setCode(response.getCode()); context.setErrorMsg(response.getRemark()); } hook.sendMessageAfter(context); } catch (Throwable e) { } } } }
Example #3
Source File: SendMessageProcessor.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 6 votes |
@Override public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { SendMessageContext mqtraceContext = null; switch (request.getCode()) { case RequestCode.CONSUMER_SEND_MSG_BACK: //客户端消费失败,重新打回的消息 return this.consumerSendMsgBack(ctx, request); default: //其他消息 SendMessageRequestHeader requestHeader = parseRequestHeader(request); //客户端producer发送的SEND_MESSAGE 等消息都在这里面解析 if (requestHeader == null) { return null; } mqtraceContext = buildMsgContext(ctx, requestHeader); this.executeSendMessageHookBefore(ctx, request, mqtraceContext); //消息处理 把接收的晓得写入commitlog等也是在这里面 final RemotingCommand response = this.sendMessage(ctx, request, mqtraceContext, requestHeader); this.executeSendMessageHookAfter(response, mqtraceContext); return response; } }
Example #4
Source File: AbstractSendMessageProcessor.java From rocketmq with Apache License 2.0 | 6 votes |
public void executeSendMessageHookAfter(final RemotingCommand response, final SendMessageContext context) { if (hasSendMessageHook()) { for (SendMessageHook hook : this.sendMessageHookList) { try { if (response != null) { final SendMessageResponseHeader responseHeader = (SendMessageResponseHeader) response.readCustomHeader(); context.setMsgId(responseHeader.getMsgId()); context.setQueueId(responseHeader.getQueueId()); context.setQueueOffset(responseHeader.getQueueOffset()); context.setCode(response.getCode()); context.setErrorMsg(response.getRemark()); } hook.sendMessageAfter(context); } catch (Throwable e) { } } } }
Example #5
Source File: SendMessageProcessor.java From rocketmq with Apache License 2.0 | 6 votes |
@Override public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { SendMessageContext mqtraceContext = null; switch (request.getCode()) { case RequestCode.CONSUMER_SEND_MSG_BACK: return this.consumerSendMsgBack(ctx, request); default: SendMessageRequestHeader requestHeader = parseRequestHeader(request); if (requestHeader == null) { return null; } mqtraceContext = buildMsgContext(ctx, requestHeader); this.executeSendMessageHookBefore(ctx, request, mqtraceContext); final RemotingCommand response = this.sendMessage(ctx, request, mqtraceContext, requestHeader); this.executeSendMessageHookAfter(response, mqtraceContext); return response; } }
Example #6
Source File: AbstractSendMessageProcessor.java From RocketMQ-Master-analyze with Apache License 2.0 | 6 votes |
public void executeSendMessageHookBefore(final ChannelHandlerContext ctx, final RemotingCommand request, SendMessageContext context) { if (hasSendMessageHook()) { for (SendMessageHook hook : this.sendMessageHookList) { try { final SendMessageRequestHeader requestHeader = (SendMessageRequestHeader) request .decodeCommandCustomHeader(SendMessageRequestHeader.class); context.setProducerGroup(requestHeader.getProducerGroup()); context.setTopic(requestHeader.getTopic()); context.setBodyLength(request.getBody().length); context.setMsgProps(requestHeader.getProperties()); context.setBornHost(RemotingHelper.parseChannelRemoteAddr(ctx.channel())); context.setBrokerAddr(this.brokerController.getBrokerAddr()); context.setQueueId(requestHeader.getQueueId()); hook.sendMessageBefore(context); requestHeader.setProperties(context.getMsgProps()); } catch (Throwable e) { } } } }
Example #7
Source File: AbstractSendMessageProcessor.java From RocketMQ-Master-analyze with Apache License 2.0 | 6 votes |
public void executeSendMessageHookAfter(final RemotingCommand response, final SendMessageContext context) { if (hasSendMessageHook()) { for (SendMessageHook hook : this.sendMessageHookList) { try { if (response != null) { final SendMessageResponseHeader responseHeader = (SendMessageResponseHeader) response.readCustomHeader(); context.setMsgId(responseHeader.getMsgId()); context.setQueueId(responseHeader.getQueueId()); context.setQueueOffset(responseHeader.getQueueOffset()); context.setCode(response.getCode()); context.setErrorMsg(response.getRemark()); } hook.sendMessageAfter(context); } catch (Throwable e) { } } } }
Example #8
Source File: SendMessageProcessor.java From RocketMQ-Master-analyze with Apache License 2.0 | 6 votes |
@Override public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { SendMessageContext mqtraceContext = null; switch (request.getCode()) { case RequestCode.CONSUMER_SEND_MSG_BACK: return this.consumerSendMsgBack(ctx, request); default: SendMessageRequestHeader requestHeader = parseRequestHeader(request); if (requestHeader == null) { return null; } // 消息轨迹:记录到达 broker 的消息 mqtraceContext = buildMsgContext(ctx, requestHeader); this.executeSendMessageHookBefore(ctx, request, mqtraceContext); final RemotingCommand response = this.sendMessage(ctx, request, mqtraceContext, requestHeader); // 消息轨迹:记录发送成功的消息 this.executeSendMessageHookAfter(response, mqtraceContext); return response; } }
Example #9
Source File: AbstractSendMessageProcessor.java From rocketmq with Apache License 2.0 | 5 votes |
public void executeSendMessageHookBefore(final ChannelHandlerContext ctx, final RemotingCommand request, SendMessageContext context) { if (hasSendMessageHook()) { for (SendMessageHook hook : this.sendMessageHookList) { try { final SendMessageRequestHeader requestHeader = parseRequestHeader(request); if (null != requestHeader) { context.setProducerGroup(requestHeader.getProducerGroup()); context.setTopic(requestHeader.getTopic()); context.setBodyLength(request.getBody().length); context.setMsgProps(requestHeader.getProperties()); context.setBornHost(RemotingHelper.parseChannelRemoteAddr(ctx.channel())); context.setBrokerAddr(this.brokerController.getBrokerAddr()); context.setQueueId(requestHeader.getQueueId()); } hook.sendMessageBefore(context); if (null != requestHeader){ requestHeader.setProperties(context.getMsgProps()); }else { log.error("executeSendMessageHookBefore parse request error."); } } catch (Throwable e) { } } } }