Search in sources :

Example 21 with RMQNormalConsumer

use of org.apache.rocketmq.test.client.rmq.RMQNormalConsumer in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class TagMessageWithSameGroupConsumerIT method testTwoConsumerWithSameGroup.

@Test
public void testTwoConsumerWithSameGroup() {
    int msgSize = 20;
    String originMsgDCName = RandomUtils.getStringByUUID();
    String msgBodyDCName = RandomUtils.getStringByUUID();
    RMQNormalConsumer consumer1 = getConsumer(nsAddr, topic, tag, new RMQNormalListner(originMsgDCName, msgBodyDCName));
    getConsumer(nsAddr, consumer1.getConsumerGroup(), tag, new RMQNormalListner(originMsgDCName, msgBodyDCName));
    producer.send(tag, msgSize);
    Assert.assertEquals("Not all are sent", msgSize, producer.getAllUndupMsgBody().size());
    consumer1.getListner().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);
    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(), consumer1.getListner().getAllMsgBody())).containsExactlyElementsIn(producer.getAllMsgBody());
}
Also used : RMQNormalListner(org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListner) RMQNormalConsumer(org.apache.rocketmq.test.client.rmq.RMQNormalConsumer) Test(org.junit.Test)

Example 22 with RMQNormalConsumer

use of org.apache.rocketmq.test.client.rmq.RMQNormalConsumer in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class OneConsumerMulTopicIT method testConsumeWithDiffTag.

@Test
public void testConsumeWithDiffTag() {
    int msgSize = 10;
    String topic1 = initTopic();
    String topic2 = initTopic();
    String tag = "jueyin_tag";
    RMQNormalConsumer consumer = getConsumer(nsAddr, topic1, "*", new RMQNormalListner());
    consumer.subscribe(topic2, tag);
    producer.send(MQMessageFactory.getMsg(topic1, msgSize));
    producer.send(MQMessageFactory.getMsg(topic2, msgSize, tag));
    Assert.assertEquals("Not all are sent", msgSize * 2, producer.getAllUndupMsgBody().size());
    consumer.getListner().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);
    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(), consumer.getListner().getAllMsgBody())).containsExactlyElementsIn(producer.getAllMsgBody());
}
Also used : RMQNormalListner(org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListner) RMQNormalConsumer(org.apache.rocketmq.test.client.rmq.RMQNormalConsumer) Test(org.junit.Test)

Example 23 with RMQNormalConsumer

use of org.apache.rocketmq.test.client.rmq.RMQNormalConsumer in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class AsyncSendWithMessageQueueIT method testAsyncSendWithMQ.

@Test
public void testAsyncSendWithMQ() {
    int msgSize = 20;
    int queueId = 0;
    RMQNormalConsumer consumer = getConsumer(nsAddr, topic, "*", new RMQNormalListner());
    MessageQueue mq = new MessageQueue(topic, broker1Name, queueId);
    producer.asyncSend(msgSize, mq);
    producer.waitForResponse(10 * 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();
    mq = new MessageQueue(topic, broker2Name, queueId);
    producer.asyncSend(msgSize, mq);
    producer.waitForResponse(10 * 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) MessageQueue(org.apache.rocketmq.common.message.MessageQueue) RMQNormalConsumer(org.apache.rocketmq.test.client.rmq.RMQNormalConsumer) Test(org.junit.Test)

Example 24 with RMQNormalConsumer

use of org.apache.rocketmq.test.client.rmq.RMQNormalConsumer in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class AsyncSendWithOnlySendCallBackIT method testSendWithOnlyCallBack.

@Test
public void testSendWithOnlyCallBack() {
    int msgSize = 20;
    RMQNormalConsumer consumer = getConsumer(nsAddr, topic, "*", new RMQNormalListner());
    producer.asyncSend(msgSize);
    producer.waitForResponse(10 * 1000);
    assertThat(producer.getSuccessMsgCount()).isEqualTo(msgSize);
    consumer.getListner().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);
    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(), consumer.getListner().getAllMsgBody())).containsExactlyElementsIn(producer.getAllMsgBody());
}
Also used : RMQNormalListner(org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListner) RMQNormalConsumer(org.apache.rocketmq.test.client.rmq.RMQNormalConsumer) Test(org.junit.Test)

Example 25 with RMQNormalConsumer

use of org.apache.rocketmq.test.client.rmq.RMQNormalConsumer in project rocketmq by apache.

the class AsyncSendWithMessageQueueSelectorIT method testSendWithSelector.

@Test
public void testSendWithSelector() {
    int msgSize = 20;
    final int queueId = 0;
    RMQNormalConsumer consumer = getConsumer(nsAddr, topic, "*", new RMQNormalListener());
    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.getListener().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);
    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(), consumer.getListener().getAllMsgBody())).containsExactlyElementsIn(producer.getAllMsgBody());
    VerifyUtils.verifyMessageQueueId(queueId, consumer.getListener().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.getListener().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);
    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(), consumer.getListener().getAllMsgBody())).containsExactlyElementsIn(producer.getAllMsgBody());
    VerifyUtils.verifyMessageQueueId(queueId, consumer.getListener().getAllOriginMsg());
}
Also used : 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) RMQNormalListener(org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListener) Test(org.junit.Test)

Aggregations

RMQNormalConsumer (org.apache.rocketmq.test.client.rmq.RMQNormalConsumer)111 Test (org.junit.Test)106 RMQNormalListener (org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListener)44 RMQNormalListner (org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListner)44 MessageQueue (org.apache.rocketmq.common.message.MessageQueue)26 RMQOrderListener (org.apache.rocketmq.test.listener.rmq.order.RMQOrderListener)18 MessageQueueMsg (org.apache.rocketmq.test.message.MessageQueueMsg)18 MQAsyncProducer (org.apache.rocketmq.test.client.mq.MQAsyncProducer)12 TagMessage (org.apache.rocketmq.test.factory.TagMessage)12 Message (org.apache.rocketmq.common.message.Message)8 MessageQueueSelector (org.apache.rocketmq.client.producer.MessageQueueSelector)4