org.apache.rocketmq.test.factory.ConsumerFactory Java Examples

The following examples show how to use org.apache.rocketmq.test.factory.ConsumerFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SqlFilterIT.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@Test
public void testFilterConsumer() throws Exception {
    int msgSize = 16;

    String group = initConsumerGroup();
    MessageSelector selector = MessageSelector.bySql("(TAGS is not null and TAGS in ('TagA', 'TagB'))");
    RMQSqlConsumer consumer = ConsumerFactory.getRMQSqlConsumer(nsAddr, group, topic, selector, new RMQNormalListener(group + "_1"));
    Thread.sleep(3000);
    producer.send("TagA", msgSize);
    producer.send("TagB", msgSize);
    producer.send("TagC", msgSize);
    Assert.assertEquals("Not all sent succeeded", msgSize * 3, producer.getAllUndupMsgBody().size());
    consumer.getListener().waitForMessageConsume(msgSize * 2, consumeTime);
    assertThat(producer.getAllMsgBody())
        .containsAllIn(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(),
            consumer.getListener().getAllMsgBody()));

    assertThat(consumer.getListener().getAllMsgBody().size()).isEqualTo(msgSize * 2);
}
 
Example #2
Source File: SqlFilterIT.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Test
public void testFilterConsumer() throws Exception {
    int msgSize = 16;

    String group = initConsumerGroup();
    MessageSelector selector = MessageSelector.bySql("(TAGS is not null and TAGS in ('TagA', 'TagB'))");
    RMQSqlConsumer consumer = ConsumerFactory.getRMQSqlConsumer(nsAddr, group, topic, selector, new RMQNormalListener(group + "_1"));
    Thread.sleep(3000);
    producer.send("TagA", msgSize);
    producer.send("TagB", msgSize);
    producer.send("TagC", msgSize);
    Assert.assertEquals("Not all sent succeeded", msgSize * 3, producer.getAllUndupMsgBody().size());
    consumer.getListener().waitForMessageConsume(msgSize * 2, consumeTime);
    assertThat(producer.getAllMsgBody())
        .containsAllIn(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(),
            consumer.getListener().getAllMsgBody()));

    assertThat(consumer.getListener().getAllMsgBody().size()).isEqualTo(msgSize * 2);
}
 
Example #3
Source File: SqlFilterIT.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
@Test
public void testFilterConsumer() throws Exception {
    int msgSize = 16;

    String group = initConsumerGroup();
    MessageSelector selector = MessageSelector.bySql("(TAGS is not null and TAGS in ('TagA', 'TagB'))");
    RMQSqlConsumer consumer = ConsumerFactory.getRMQSqlConsumer(nsAddr, group, topic, selector, new RMQNormalListener(group + "_1"));
    Thread.sleep(3000);
    producer.send("TagA", msgSize);
    producer.send("TagB", msgSize);
    producer.send("TagC", msgSize);
    Assert.assertEquals("Not all sent succeeded", msgSize * 3, producer.getAllUndupMsgBody().size());
    consumer.getListener().waitForMessageConsume(msgSize * 2, consumeTime);
    assertThat(producer.getAllMsgBody())
        .containsAllIn(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(),
            consumer.getListener().getAllMsgBody()));

    assertThat(consumer.getListener().getAllMsgBody().size()).isEqualTo(msgSize * 2);
}
 
Example #4
Source File: SqlFilterIT.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
@Test
public void testFilterConsumer() throws Exception {
    int msgSize = 16;

    String group = initConsumerGroup();
    MessageSelector selector = MessageSelector.bySql("(TAGS is not null and TAGS in ('TagA', 'TagB'))");
    RMQSqlConsumer consumer = ConsumerFactory.getRMQSqlConsumer(nsAddr, group, topic, selector, new RMQNormalListener(group + "_1"));
    Thread.sleep(3000);
    producer.send("TagA", msgSize);
    producer.send("TagB", msgSize);
    producer.send("TagC", msgSize);
    Assert.assertEquals("Not all sent succeeded", msgSize * 3, producer.getAllUndupMsgBody().size());
    consumer.getListener().waitForMessageConsume(msgSize * 2, consumeTime);
    assertThat(producer.getAllMsgBody())
        .containsAllIn(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(),
            consumer.getListener().getAllMsgBody()));

    assertThat(consumer.getListener().getAllMsgBody().size()).isEqualTo(msgSize * 2);
}
 
Example #5
Source File: SqlFilterIT.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
@Test
public void testFilterConsumer() throws Exception {
    int msgSize = 16;

    String group = initConsumerGroup();
    MessageSelector selector = MessageSelector.bySql("(TAGS is not null and TAGS in ('TagA', 'TagB'))");
    RMQSqlConsumer consumer = ConsumerFactory.getRMQSqlConsumer(nsAddr, group, topic, selector, new RMQNormalListner(group + "_1"));
    Thread.sleep(3000);
    producer.send("TagA", msgSize);
    producer.send("TagB", msgSize);
    producer.send("TagC", msgSize);
    Assert.assertEquals("Not all sent succeeded", msgSize * 3, producer.getAllUndupMsgBody().size());
    consumer.getListner().waitForMessageConsume(msgSize * 2, consumeTime);
    assertThat(producer.getAllMsgBody())
        .containsAllIn(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(),
        consumer.getListner().getAllMsgBody()));

    assertThat(consumer.getListner().getAllMsgBody().size()).isEqualTo(msgSize * 2);
}
 
Example #6
Source File: SqlFilterIT.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Test
public void testFilterConsumer() throws Exception {
    int msgSize = 16;

    String group = initConsumerGroup();
    MessageSelector selector = MessageSelector.bySql("(TAGS is not null and TAGS in ('TagA', 'TagB'))");
    RMQSqlConsumer consumer = ConsumerFactory.getRMQSqlConsumer(nsAddr, group, topic, selector, new RMQNormalListener(group + "_1"));
    Thread.sleep(3000);
    producer.send("TagA", msgSize);
    producer.send("TagB", msgSize);
    producer.send("TagC", msgSize);
    Assert.assertEquals("Not all sent succeeded", msgSize * 3, producer.getAllUndupMsgBody().size());
    consumer.getListener().waitForMessageConsume(msgSize * 2, consumeTime);
    assertThat(producer.getAllMsgBody())
        .containsAllIn(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(),
            consumer.getListener().getAllMsgBody()));

    assertThat(consumer.getListener().getAllMsgBody().size()).isEqualTo(msgSize * 2);
}
 
Example #7
Source File: BaseConf.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public static RMQNormalConsumer getConsumer(String nsAddr, String consumerGroup, String topic,
    String subExpression, AbstractListener listener, boolean useTLS) {
    RMQNormalConsumer consumer = ConsumerFactory.getRMQNormalConsumer(nsAddr, consumerGroup,
        topic, subExpression, listener, useTLS);
    if (debug) {
        consumer.setDebug();
    }
    mqClients.add(consumer);
    log.info(String.format("consumer[%s] start,topic[%s],subExpression[%s]", consumerGroup,
        topic, subExpression));
    return consumer;
}
 
Example #8
Source File: BaseBroadCastIT.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public static RMQBroadCastConsumer getBroadCastConsumer(String nsAddr, String consumerGroup,
    String topic, String subExpression,
    AbstractListener listner) {
    RMQBroadCastConsumer consumer = ConsumerFactory.getRMQBroadCastConsumer(nsAddr,
        consumerGroup, topic, subExpression, listner);

    consumer.setDebug();

    mqClients.add(consumer);
    logger.info(String.format("consumer[%s] start,topic[%s],subExpression[%s]", consumerGroup,
        topic, subExpression));
    return consumer;
}
 
Example #9
Source File: BaseConf.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public static RMQNormalConsumer getConsumer(String nsAddr, String consumerGroup, String topic,
    String subExpression, AbstractListener listener, boolean useTLS) {
    RMQNormalConsumer consumer = ConsumerFactory.getRMQNormalConsumer(nsAddr, consumerGroup,
        topic, subExpression, listener, useTLS);
    if (debug) {
        consumer.setDebug();
    }
    mqClients.add(consumer);
    log.info(String.format("consumer[%s] start,topic[%s],subExpression[%s]", consumerGroup,
        topic, subExpression));
    return consumer;
}
 
Example #10
Source File: BaseBroadCastIT.java    From rocketmq_trans_message with Apache License 2.0 5 votes vote down vote up
public static RMQBroadCastConsumer getBroadCastConsumer(String nsAddr, String consumerGroup,
    String topic, String subExpression,
    AbstractListener listner) {
    RMQBroadCastConsumer consumer = ConsumerFactory.getRMQBroadCastConsumer(nsAddr,
        consumerGroup, topic, subExpression, listner);

    consumer.setDebug();

    mqClients.add(consumer);
    logger.info(String.format("consumer[%s] start,topic[%s],subExpression[%s]", consumerGroup,
        topic, subExpression));
    return consumer;
}
 
Example #11
Source File: BaseConf.java    From rocketmq_trans_message with Apache License 2.0 5 votes vote down vote up
public static RMQNormalConsumer getConsumer(String nsAddr, String consumerGroup, String topic,
    String subExpression, AbstractListener listner) {
    RMQNormalConsumer consumer = ConsumerFactory.getRMQNormalConsumer(nsAddr, consumerGroup,
        topic, subExpression, listner);
    if (debug) {
        consumer.setDebug();
    }
    mqClients.add(consumer);
    log.info(String.format("consumer[%s] start,topic[%s],subExpression[%s]", consumerGroup,
        topic, subExpression));
    return consumer;
}
 
Example #12
Source File: BaseBroadCastIT.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
public static RMQBroadCastConsumer getBroadCastConsumer(String nsAddr, String consumerGroup,
    String topic, String subExpression,
    AbstractListener listner) {
    RMQBroadCastConsumer consumer = ConsumerFactory.getRMQBroadCastConsumer(nsAddr,
        consumerGroup, topic, subExpression, listner);

    consumer.setDebug();

    mqClients.add(consumer);
    logger.info(String.format("consumer[%s] start,topic[%s],subExpression[%s]", consumerGroup,
        topic, subExpression));
    return consumer;
}
 
Example #13
Source File: BaseConf.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
public static RMQNormalConsumer getConsumer(String nsAddr, String consumerGroup, String topic,
    String subExpression, AbstractListener listner) {
    RMQNormalConsumer consumer = ConsumerFactory.getRMQNormalConsumer(nsAddr, consumerGroup,
        topic, subExpression, listner);
    if (debug) {
        consumer.setDebug();
    }
    mqClients.add(consumer);
    log.info(String.format("consumer[%s] start,topic[%s],subExpression[%s]", consumerGroup,
        topic, subExpression));
    return consumer;
}
 
Example #14
Source File: BaseBroadCastIT.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public static RMQBroadCastConsumer getBroadCastConsumer(String nsAddr, String consumerGroup,
    String topic, String subExpression,
    AbstractListener listner) {
    RMQBroadCastConsumer consumer = ConsumerFactory.getRMQBroadCastConsumer(nsAddr,
        consumerGroup, topic, subExpression, listner);

    consumer.setDebug();

    mqClients.add(consumer);
    logger.info(String.format("consumer[%s] start,topic[%s],subExpression[%s]", consumerGroup,
        topic, subExpression));
    return consumer;
}
 
Example #15
Source File: BaseConf.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public static RMQNormalConsumer getConsumer(String nsAddr, String consumerGroup, String topic,
    String subExpression, AbstractListener listener, boolean useTLS) {
    RMQNormalConsumer consumer = ConsumerFactory.getRMQNormalConsumer(nsAddr, consumerGroup,
        topic, subExpression, listener, useTLS);
    if (debug) {
        consumer.setDebug();
    }
    mqClients.add(consumer);
    log.info(String.format("consumer[%s] start,topic[%s],subExpression[%s]", consumerGroup,
        topic, subExpression));
    return consumer;
}
 
Example #16
Source File: BaseBroadCastIT.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public static RMQBroadCastConsumer getBroadCastConsumer(String nsAddr, String consumerGroup,
    String topic, String subExpression,
    AbstractListener listner) {
    RMQBroadCastConsumer consumer = ConsumerFactory.getRMQBroadCastConsumer(nsAddr,
        consumerGroup, topic, subExpression, listner);

    consumer.setDebug();

    mqClients.add(consumer);
    logger.info(String.format("consumer[%s] start,topic[%s],subExpression[%s]", consumerGroup,
        topic, subExpression));
    return consumer;
}
 
Example #17
Source File: BaseConf.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public static RMQNormalConsumer getConsumer(String nsAddr, String consumerGroup, String topic,
    String subExpression, AbstractListener listner) {
    RMQNormalConsumer consumer = ConsumerFactory.getRMQNormalConsumer(nsAddr, consumerGroup,
        topic, subExpression, listner);
    if (debug) {
        consumer.setDebug();
    }
    mqClients.add(consumer);
    log.info(String.format("consumer[%s] start,topic[%s],subExpression[%s]", consumerGroup,
        topic, subExpression));
    return consumer;
}
 
Example #18
Source File: BaseBroadCastIT.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
public static RMQBroadCastConsumer getBroadCastConsumer(String nsAddr, String consumerGroup,
    String topic, String subExpression,
    AbstractListener listner) {
    RMQBroadCastConsumer consumer = ConsumerFactory.getRMQBroadCastConsumer(nsAddr,
        consumerGroup, topic, subExpression, listner);

    consumer.setDebug();

    mqClients.add(consumer);
    logger.info(String.format("consumer[%s] start,topic[%s],subExpression[%s]", consumerGroup,
        topic, subExpression));
    return consumer;
}
 
Example #19
Source File: BaseConf.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
public static RMQNormalConsumer getConsumer(String nsAddr, String consumerGroup, String topic,
    String subExpression, AbstractListener listener, boolean useTLS) {
    RMQNormalConsumer consumer = ConsumerFactory.getRMQNormalConsumer(nsAddr, consumerGroup,
        topic, subExpression, listener, useTLS);
    if (debug) {
        consumer.setDebug();
    }
    mqClients.add(consumer);
    log.info(String.format("consumer[%s] start,topic[%s],subExpression[%s]", consumerGroup,
        topic, subExpression));
    return consumer;
}
 
Example #20
Source File: BaseBroadCastIT.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
public static RMQBroadCastConsumer getBroadCastConsumer(String nsAddr, String consumerGroup,
    String topic, String subExpression,
    AbstractListener listner) {
    RMQBroadCastConsumer consumer = ConsumerFactory.getRMQBroadCastConsumer(nsAddr,
        consumerGroup, topic, subExpression, listner);

    consumer.setDebug();

    mqClients.add(consumer);
    logger.info(String.format("consumer[%s] start,topic[%s],subExpression[%s]", consumerGroup,
        topic, subExpression));
    return consumer;
}
 
Example #21
Source File: BaseConf.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
public static RMQNormalConsumer getConsumer(String nsAddr, String consumerGroup, String topic,
    String subExpression, AbstractListener listener, boolean useTLS) {
    RMQNormalConsumer consumer = ConsumerFactory.getRMQNormalConsumer(nsAddr, consumerGroup,
        topic, subExpression, listener, useTLS);
    if (debug) {
        consumer.setDebug();
    }
    mqClients.add(consumer);
    log.info(String.format("consumer[%s] start,topic[%s],subExpression[%s]", consumerGroup,
        topic, subExpression));
    return consumer;
}
 
Example #22
Source File: BaseBroadCastIT.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public static RMQBroadCastConsumer getBroadCastConsumer(String nsAddr, String consumerGroup,
    String topic, String subExpression,
    AbstractListener listner) {
    RMQBroadCastConsumer consumer = ConsumerFactory.getRMQBroadCastConsumer(nsAddr,
        consumerGroup, topic, subExpression, listner);

    consumer.setDebug();

    mqClients.add(consumer);
    logger.info(String.format("consumer[%s] start,topic[%s],subExpression[%s]", consumerGroup,
        topic, subExpression));
    return consumer;
}
 
Example #23
Source File: DLedgerProduceAndConsumeIT.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
@Test
public void testProduceAndConsume() throws Exception {
    String cluster = UUID.randomUUID().toString();
    String brokerName = UUID.randomUUID().toString();
    String selfId = "n0";
    String peers = String.format("n0-localhost:%d", nextPort());
    BrokerConfig brokerConfig = buildBrokerConfig(cluster, brokerName);
    MessageStoreConfig storeConfig = buildStoreConfig(brokerName, peers, selfId);
    BrokerController brokerController = IntegrationTestBase.createAndStartBroker(storeConfig, brokerConfig);
    Thread.sleep(3000);

    Assert.assertEquals(BrokerRole.SYNC_MASTER, storeConfig.getBrokerRole());


    String topic = UUID.randomUUID().toString();
    String consumerGroup = UUID.randomUUID().toString();
    IntegrationTestBase.initTopic(topic, BaseConf.nsAddr, cluster, 1);
    DefaultMQProducer producer = ProducerFactory.getRMQProducer(BaseConf.nsAddr);
    DefaultMQPullConsumer consumer = ConsumerFactory.getRMQPullConsumer(BaseConf.nsAddr, consumerGroup);

    for (int i = 0; i < 10; i++) {
        Message message = new Message();
        message.setTopic(topic);
        message.setBody(("Hello" + i).getBytes());
        SendResult sendResult = producer.send(message);
        Assert.assertEquals(SendStatus.SEND_OK, sendResult.getSendStatus());
        Assert.assertEquals(0, sendResult.getMessageQueue().getQueueId());
        Assert.assertEquals(brokerName, sendResult.getMessageQueue().getBrokerName());
        Assert.assertEquals(i, sendResult.getQueueOffset());
        Assert.assertNotNull(sendResult.getMsgId());
        Assert.assertNotNull(sendResult.getOffsetMsgId());
    }

    Thread.sleep(500);
    Assert.assertEquals(0, brokerController.getMessageStore().getMinOffsetInQueue(topic, 0));
    Assert.assertEquals(10, brokerController.getMessageStore().getMaxOffsetInQueue(topic, 0));

    MessageQueue messageQueue = new MessageQueue(topic, brokerName, 0);
    PullResult pullResult= consumer.pull(messageQueue, "*", 0, 32);
    Assert.assertEquals(PullStatus.FOUND, pullResult.getPullStatus());
    Assert.assertEquals(10, pullResult.getMsgFoundList().size());

    for (int i = 0; i < 10; i++) {
        MessageExt messageExt = pullResult.getMsgFoundList().get(i);
        Assert.assertEquals(i, messageExt.getQueueOffset());
        Assert.assertArrayEquals(("Hello" + i).getBytes(), messageExt.getBody());
    }

    producer.shutdown();
    consumer.shutdown();
    brokerController.shutdown();
}