Search in sources :

Example 6 with SendMessageHook

use of org.apache.rocketmq.broker.mqtrace.SendMessageHook in project rocketmq by apache.

the class AbstractSendMessageProcessor method executeSendMessageHookBefore.

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 (requestHeader != null) {
                    requestHeader.setProperties(context.getMsgProps());
                }
            } catch (Throwable e) {
            // Ignore
            }
        }
    }
}
Also used : SendMessageRequestHeader(org.apache.rocketmq.common.protocol.header.SendMessageRequestHeader) SendMessageHook(org.apache.rocketmq.broker.mqtrace.SendMessageHook)

Aggregations

SendMessageHook (org.apache.rocketmq.broker.mqtrace.SendMessageHook)6 ArrayList (java.util.ArrayList)2 SendMessageContext (org.apache.rocketmq.broker.mqtrace.SendMessageContext)2 SendMessageRequestHeader (org.apache.rocketmq.common.protocol.header.SendMessageRequestHeader)2 SendMessageResponseHeader (org.apache.rocketmq.common.protocol.header.SendMessageResponseHeader)2 AppendMessageResult (org.apache.rocketmq.store.AppendMessageResult)2 MessageExtBrokerInner (org.apache.rocketmq.store.MessageExtBrokerInner)2 PutMessageResult (org.apache.rocketmq.store.PutMessageResult)2 Test (org.junit.Test)2