Search in sources :

Example 1 with ConsumeMessageConcurrentlyService

use of org.apache.rocketmq.client.impl.consumer.ConsumeMessageConcurrentlyService in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class DefaultMQPushConsumerTest method testPullMessage_Success.

@Test
public void testPullMessage_Success() throws InterruptedException, RemotingException, MQBrokerException {
    final CountDownLatch countDownLatch = new CountDownLatch(1);
    final MessageExt[] messageExts = new MessageExt[1];
    pushConsumer.getDefaultMQPushConsumerImpl().setConsumeMessageService(new ConsumeMessageConcurrentlyService(pushConsumer.getDefaultMQPushConsumerImpl(), new MessageListenerConcurrently() {

        @Override
        public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext context) {
            messageExts[0] = msgs.get(0);
            countDownLatch.countDown();
            return null;
        }
    }));
    PullMessageService pullMessageService = mQClientFactory.getPullMessageService();
    pullMessageService.executePullRequestImmediately(createPullRequest());
    countDownLatch.await();
    assertThat(messageExts[0].getTopic()).isEqualTo(topic);
    assertThat(messageExts[0].getBody()).isEqualTo(new byte[] { 'a' });
}
Also used : ConsumeConcurrentlyContext(org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext) PullMessageService(org.apache.rocketmq.client.impl.consumer.PullMessageService) MessageExt(org.apache.rocketmq.common.message.MessageExt) MessageListenerConcurrently(org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently) ConsumeMessageConcurrentlyService(org.apache.rocketmq.client.impl.consumer.ConsumeMessageConcurrentlyService) List(java.util.List) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 2 with ConsumeMessageConcurrentlyService

use of org.apache.rocketmq.client.impl.consumer.ConsumeMessageConcurrentlyService in project rocketmq by apache.

the class DefaultMQPushConsumerTest method testPullMessage_Success.

@Test
public void testPullMessage_Success() throws InterruptedException, RemotingException, MQBrokerException {
    final CountDownLatch countDownLatch = new CountDownLatch(1);
    final MessageExt[] messageExts = new MessageExt[1];
    pushConsumer.getDefaultMQPushConsumerImpl().setConsumeMessageService(new ConsumeMessageConcurrentlyService(pushConsumer.getDefaultMQPushConsumerImpl(), new MessageListenerConcurrently() {

        @Override
        public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext context) {
            messageExts[0] = msgs.get(0);
            countDownLatch.countDown();
            return null;
        }
    }));
    PullMessageService pullMessageService = mQClientFactory.getPullMessageService();
    pullMessageService.executePullRequestImmediately(createPullRequest());
    countDownLatch.await();
    assertThat(messageExts[0].getTopic()).isEqualTo(topic);
    assertThat(messageExts[0].getBody()).isEqualTo(new byte[] { 'a' });
}
Also used : ConsumeConcurrentlyContext(org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext) PullMessageService(org.apache.rocketmq.client.impl.consumer.PullMessageService) MessageExt(org.apache.rocketmq.common.message.MessageExt) MessageListenerConcurrently(org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently) ConsumeMessageConcurrentlyService(org.apache.rocketmq.client.impl.consumer.ConsumeMessageConcurrentlyService) List(java.util.List) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

List (java.util.List)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ConsumeConcurrentlyContext (org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext)2 MessageListenerConcurrently (org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently)2 ConsumeMessageConcurrentlyService (org.apache.rocketmq.client.impl.consumer.ConsumeMessageConcurrentlyService)2 PullMessageService (org.apache.rocketmq.client.impl.consumer.PullMessageService)2 MessageExt (org.apache.rocketmq.common.message.MessageExt)2 Test (org.junit.Test)2