Search in sources :

Example 1 with ConsumeMessageHook

use of org.apache.rocketmq.broker.mqtrace.ConsumeMessageHook in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class PullMessageProcessorTest method testProcessRequest_FoundWithHook.

@Test
public void testProcessRequest_FoundWithHook() throws RemotingCommandException {
    GetMessageResult getMessageResult = createGetMessageResult();
    when(messageStore.getMessage(anyString(), anyString(), anyInt(), anyLong(), anyInt(), any(ExpressionMessageFilter.class))).thenReturn(getMessageResult);
    List<ConsumeMessageHook> consumeMessageHookList = new ArrayList<>();
    final ConsumeMessageContext[] messageContext = new ConsumeMessageContext[1];
    ConsumeMessageHook consumeMessageHook = new ConsumeMessageHook() {

        @Override
        public String hookName() {
            return "TestHook";
        }

        @Override
        public void consumeMessageBefore(ConsumeMessageContext context) {
            messageContext[0] = context;
        }

        @Override
        public void consumeMessageAfter(ConsumeMessageContext context) {
        }
    };
    consumeMessageHookList.add(consumeMessageHook);
    pullMessageProcessor.registerConsumeMessageHook(consumeMessageHookList);
    final RemotingCommand request = createPullMsgCommand(RequestCode.PULL_MESSAGE);
    RemotingCommand response = pullMessageProcessor.processRequest(handlerContext, request);
    assertThat(response).isNotNull();
    assertThat(response.getCode()).isEqualTo(ResponseCode.SUCCESS);
    assertThat(messageContext[0]).isNotNull();
    assertThat(messageContext[0].getConsumerGroup()).isEqualTo(group);
    assertThat(messageContext[0].getTopic()).isEqualTo(topic);
    assertThat(messageContext[0].getQueueId()).isEqualTo(1);
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) ConsumeMessageContext(org.apache.rocketmq.broker.mqtrace.ConsumeMessageContext) GetMessageResult(org.apache.rocketmq.store.GetMessageResult) ConsumeMessageHook(org.apache.rocketmq.broker.mqtrace.ConsumeMessageHook) ExpressionMessageFilter(org.apache.rocketmq.broker.filter.ExpressionMessageFilter) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with ConsumeMessageHook

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

the class PullMessageProcessorTest method testProcessRequest_FoundWithHook.

@Test
public void testProcessRequest_FoundWithHook() throws RemotingCommandException {
    GetMessageResult getMessageResult = createGetMessageResult();
    when(messageStore.getMessage(anyString(), anyString(), anyInt(), anyLong(), anyInt(), any(ExpressionMessageFilter.class))).thenReturn(getMessageResult);
    List<ConsumeMessageHook> consumeMessageHookList = new ArrayList<>();
    final ConsumeMessageContext[] messageContext = new ConsumeMessageContext[1];
    ConsumeMessageHook consumeMessageHook = new ConsumeMessageHook() {

        @Override
        public String hookName() {
            return "TestHook";
        }

        @Override
        public void consumeMessageBefore(ConsumeMessageContext context) {
            messageContext[0] = context;
        }

        @Override
        public void consumeMessageAfter(ConsumeMessageContext context) {
        }
    };
    consumeMessageHookList.add(consumeMessageHook);
    pullMessageProcessor.registerConsumeMessageHook(consumeMessageHookList);
    final RemotingCommand request = createPullMsgCommand(RequestCode.PULL_MESSAGE);
    RemotingCommand response = pullMessageProcessor.processRequest(handlerContext, request);
    assertThat(response).isNotNull();
    assertThat(response.getCode()).isEqualTo(ResponseCode.SUCCESS);
    assertThat(messageContext[0]).isNotNull();
    assertThat(messageContext[0].getConsumerGroup()).isEqualTo(group);
    assertThat(messageContext[0].getTopic()).isEqualTo(topic);
    assertThat(messageContext[0].getQueueId()).isEqualTo(1);
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) ConsumeMessageContext(org.apache.rocketmq.broker.mqtrace.ConsumeMessageContext) GetMessageResult(org.apache.rocketmq.store.GetMessageResult) ConsumeMessageHook(org.apache.rocketmq.broker.mqtrace.ConsumeMessageHook) ExpressionMessageFilter(org.apache.rocketmq.broker.filter.ExpressionMessageFilter) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)2 ExpressionMessageFilter (org.apache.rocketmq.broker.filter.ExpressionMessageFilter)2 ConsumeMessageContext (org.apache.rocketmq.broker.mqtrace.ConsumeMessageContext)2 ConsumeMessageHook (org.apache.rocketmq.broker.mqtrace.ConsumeMessageHook)2 RemotingCommand (org.apache.rocketmq.remoting.protocol.RemotingCommand)2 GetMessageResult (org.apache.rocketmq.store.GetMessageResult)2 Test (org.junit.Test)2