Search in sources :

Example 31 with RMQNormalListner

use of org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListner in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class MulConsumerMulTopicIT method testConsumeWithDiffTagAndFilter.

@Test
public void testConsumeWithDiffTagAndFilter() {
    int msgSize = 10;
    String topic1 = initTopic();
    String topic2 = initTopic();
    String tag1 = "jueyin_tag_1";
    String tag2 = "jueyin_tag_2";
    RMQNormalConsumer consumer1 = getConsumer(nsAddr, topic1, "*", new RMQNormalListner());
    consumer1.subscribe(topic2, tag1);
    RMQNormalConsumer consumer2 = getConsumer(nsAddr, topic1, "*", new RMQNormalListner());
    consumer2.subscribe(topic2, tag1);
    producer.send(MQMessageFactory.getMsg(topic2, msgSize, tag2));
    producer.clearMsg();
    producer.send(MQMessageFactory.getMsg(topic1, msgSize));
    producer.send(MQMessageFactory.getMsg(topic2, msgSize, tag1));
    boolean recvAll = MQWait.waitConsumeAll(consumeTime, producer.getAllMsgBody(), consumer1.getListner(), consumer2.getListner());
    assertThat(recvAll).isEqualTo(true);
}
Also used : RMQNormalListner(org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListner) RMQNormalConsumer(org.apache.rocketmq.test.client.rmq.RMQNormalConsumer) Test(org.junit.Test)

Example 32 with RMQNormalListner

use of org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListner in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class MulConsumerMulTopicIT method testConsumeWithDiffTag.

@Test
public void testConsumeWithDiffTag() {
    int msgSize = 10;
    String topic1 = initTopic();
    String topic2 = initTopic();
    String tag = "jueyin_tag";
    RMQNormalConsumer consumer1 = getConsumer(nsAddr, topic1, "*", new RMQNormalListner());
    consumer1.subscribe(topic2, tag);
    RMQNormalConsumer consumer2 = getConsumer(nsAddr, consumer1.getConsumerGroup(), topic1, "*", new RMQNormalListner());
    consumer2.subscribe(topic2, tag);
    producer.send(MQMessageFactory.getMsg(topic1, msgSize));
    producer.send(MQMessageFactory.getMsg(topic2, msgSize, tag));
    Assert.assertEquals("Not all sent succeeded", msgSize * 2, producer.getAllUndupMsgBody().size());
    boolean recvAll = MQWait.waitConsumeAll(consumeTime, producer.getAllMsgBody(), consumer1.getListner(), consumer2.getListner());
    assertThat(recvAll).isEqualTo(true);
}
Also used : RMQNormalListner(org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListner) RMQNormalConsumer(org.apache.rocketmq.test.client.rmq.RMQNormalConsumer) Test(org.junit.Test)

Example 33 with RMQNormalListner

use of org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListner in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class MulConsumerMulTopicIT method testSynSendMessage.

@Test
public void testSynSendMessage() {
    int msgSize = 10;
    String topic1 = initTopic();
    String topic2 = initTopic();
    RMQNormalConsumer consumer1 = getConsumer(nsAddr, topic1, "*", new RMQNormalListner());
    consumer1.subscribe(topic2, "*");
    RMQNormalConsumer consumer2 = getConsumer(nsAddr, consumer1.getConsumerGroup(), topic1, "*", new RMQNormalListner());
    consumer2.subscribe(topic2, "*");
    producer.send(MQMessageFactory.getMsg(topic1, msgSize));
    producer.send(MQMessageFactory.getMsg(topic2, msgSize));
    Assert.assertEquals("Not all sent succeeded", msgSize * 2, producer.getAllUndupMsgBody().size());
    boolean recvAll = MQWait.waitConsumeAll(consumeTime, producer.getAllMsgBody(), consumer1.getListner(), consumer2.getListner());
    assertThat(recvAll).isEqualTo(true);
}
Also used : RMQNormalListner(org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListner) RMQNormalConsumer(org.apache.rocketmq.test.client.rmq.RMQNormalConsumer) Test(org.junit.Test)

Example 34 with RMQNormalListner

use of org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListner in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class AsyncSendWithMessageQueueSelectorIT method testSendWithSelector.

@Test
public void testSendWithSelector() {
    int msgSize = 20;
    final int queueId = 0;
    RMQNormalConsumer consumer = getConsumer(nsAddr, topic, "*", new RMQNormalListner());
    producer.asyncSend(msgSize, new MessageQueueSelector() {

        @Override
        public MessageQueue select(List<MessageQueue> list, Message message, Object o) {
            for (MessageQueue mq : list) {
                if (mq.getQueueId() == queueId && mq.getBrokerName().equals(broker1Name)) {
                    return mq;
                }
            }
            return list.get(0);
        }
    });
    producer.waitForResponse(5 * 1000);
    assertThat(producer.getSuccessMsgCount()).isEqualTo(msgSize);
    consumer.getListner().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);
    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(), consumer.getListner().getAllMsgBody())).containsExactlyElementsIn(producer.getAllMsgBody());
    VerifyUtils.verifyMessageQueueId(queueId, consumer.getListner().getAllOriginMsg());
    producer.clearMsg();
    consumer.clearMsg();
    producer.getSuccessSendResult().clear();
    producer.asyncSend(msgSize, new MessageQueueSelector() {

        @Override
        public MessageQueue select(List<MessageQueue> list, Message message, Object o) {
            for (MessageQueue mq : list) {
                if (mq.getQueueId() == queueId && mq.getBrokerName().equals(broker2Name)) {
                    return mq;
                }
            }
            return list.get(8);
        }
    });
    producer.waitForResponse(5 * 1000);
    assertThat(producer.getSuccessMsgCount()).isEqualTo(msgSize);
    consumer.getListner().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);
    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(), consumer.getListner().getAllMsgBody())).containsExactlyElementsIn(producer.getAllMsgBody());
    VerifyUtils.verifyMessageQueueId(queueId, consumer.getListner().getAllOriginMsg());
}
Also used : RMQNormalListner(org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListner) MessageQueueSelector(org.apache.rocketmq.client.producer.MessageQueueSelector) MessageQueue(org.apache.rocketmq.common.message.MessageQueue) Message(org.apache.rocketmq.common.message.Message) RMQNormalConsumer(org.apache.rocketmq.test.client.rmq.RMQNormalConsumer) Test(org.junit.Test)

Example 35 with RMQNormalListner

use of org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListner in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class OneWaySendWithSelectorIT method testSendWithSelector.

@Test
public void testSendWithSelector() {
    int msgSize = 20;
    final int queueId = 0;
    RMQNormalConsumer consumer = getConsumer(nsAddr, topic, "*", new RMQNormalListner());
    producer.sendOneWay(msgSize, new MessageQueueSelector() {

        @Override
        public MessageQueue select(List<MessageQueue> list, Message message, Object o) {
            for (MessageQueue mq : list) {
                if (mq.getQueueId() == queueId && mq.getBrokerName().equals(broker1Name)) {
                    return mq;
                }
            }
            return list.get(0);
        }
    });
    assertThat(producer.getAllMsgBody().size()).isEqualTo(msgSize);
    consumer.getListner().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);
    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(), consumer.getListner().getAllMsgBody())).containsExactlyElementsIn(producer.getAllMsgBody());
    VerifyUtils.verifyMessageQueueId(queueId, consumer.getListner().getAllOriginMsg());
    producer.clearMsg();
    consumer.clearMsg();
    producer.sendOneWay(msgSize, new MessageQueueSelector() {

        @Override
        public MessageQueue select(List<MessageQueue> list, Message message, Object o) {
            for (MessageQueue mq : list) {
                if (mq.getQueueId() == queueId && mq.getBrokerName().equals(broker2Name)) {
                    return mq;
                }
            }
            return list.get(8);
        }
    });
    assertThat(producer.getAllMsgBody().size()).isEqualTo(msgSize);
    consumer.getListner().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);
    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(), consumer.getListner().getAllMsgBody())).containsExactlyElementsIn(producer.getAllMsgBody());
    VerifyUtils.verifyMessageQueueId(queueId, consumer.getListner().getAllOriginMsg());
}
Also used : RMQNormalListner(org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListner) MessageQueueSelector(org.apache.rocketmq.client.producer.MessageQueueSelector) MessageQueue(org.apache.rocketmq.common.message.MessageQueue) Message(org.apache.rocketmq.common.message.Message) RMQNormalConsumer(org.apache.rocketmq.test.client.rmq.RMQNormalConsumer) Test(org.junit.Test)

Aggregations

RMQNormalListner (org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListner)54 Test (org.junit.Test)54 RMQNormalConsumer (org.apache.rocketmq.test.client.rmq.RMQNormalConsumer)44 RMQBroadCastConsumer (org.apache.rocketmq.test.client.rmq.RMQBroadCastConsumer)9 MQAsyncProducer (org.apache.rocketmq.test.client.mq.MQAsyncProducer)6 TagMessage (org.apache.rocketmq.test.factory.TagMessage)6 Message (org.apache.rocketmq.common.message.Message)4 MessageQueue (org.apache.rocketmq.common.message.MessageQueue)4 MessageQueueSelector (org.apache.rocketmq.client.producer.MessageQueueSelector)2 MessageSelector (org.apache.rocketmq.client.consumer.MessageSelector)1 RMQSqlConsumer (org.apache.rocketmq.test.client.rmq.RMQSqlConsumer)1