use of org.apache.rocketmq.client.consumer.DefaultMQPushConsumer in project ignite by apache.
the class RocketMQStreamer method start.
/**
* Starts streamer.
*
* @throws IgniteException If failed.
*/
public void start() {
if (!stopped)
throw new IgniteException("Attempted to start an already started RocketMQ streamer");
// validate parameters.
A.notNull(getStreamer(), "streamer");
A.notNull(getIgnite(), "ignite");
A.notNull(topic, "topic");
A.notNull(consumerGrp, "consumer group");
A.notNullOrEmpty(nameSrvAddr, "nameserver address");
A.ensure(null != getMultipleTupleExtractor(), "Multiple tuple extractor must be configured");
log = getIgnite().log();
consumer = new DefaultMQPushConsumer(consumerGrp);
consumer.setNamesrvAddr(nameSrvAddr);
consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_LAST_OFFSET);
try {
consumer.subscribe(topic, "*");
} catch (MQClientException e) {
throw new IgniteException("Failed to subscribe to " + topic, e);
}
consumer.registerMessageListener(this);
try {
consumer.start();
} catch (MQClientException e) {
throw new IgniteException("Failed to start the streamer", e);
}
stopped = false;
}
use of org.apache.rocketmq.client.consumer.DefaultMQPushConsumer in project rocketmq-externals by apache.
the class RocketMQConsoleTestBase method startTestMQConsumer.
protected void startTestMQConsumer() {
// test online consumer
consumer = new DefaultMQPushConsumer(TEST_CONSUMER_GROUP);
consumerConfigInfo.setBrokerNameList(Lists.newArrayList(TestConstant.TEST_BROKER_NAME));
SubscriptionGroupConfig subscriptionGroupConfig = new SubscriptionGroupConfig();
subscriptionGroupConfig.setGroupName(TEST_CONSUMER_GROUP);
subscriptionGroupConfig.setRetryQueueNums(RETRY_QUEUE_NUMS);
consumerConfigInfo.setSubscriptionGroupConfig(subscriptionGroupConfig);
consumerService.createAndUpdateSubscriptionGroupConfig(consumerConfigInfo);
consumer.setNamesrvAddr(TestConstant.NAME_SERVER_ADDRESS);
consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
try {
consumer.subscribe(TEST_CONSOLE_TOPIC, "*");
consumer.registerMessageListener(new MessageListenerConcurrently() {
@Override
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext context) {
consoleTestBaseLog.info("op=consumeMessage message={}", JsonUtil.obj2String(msgs));
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
});
consumer.start();
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
use of org.apache.rocketmq.client.consumer.DefaultMQPushConsumer in project rocketmq-externals by apache.
the class ConsumerTest method main.
public static void main(String[] args) {
DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("g00003");
consumer.setNamesrvAddr("localhost:9876");
try {
consumer.subscribe("flink-sink2", "*");
} catch (MQClientException e) {
e.printStackTrace();
}
consumer.registerMessageListener(new MessageListenerConcurrently() {
@Override
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext context) {
for (MessageExt msg : msgs) {
System.out.println(msg.getKeys() + ":" + new String(msg.getBody()));
}
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
});
try {
consumer.start();
} catch (MQClientException e) {
e.printStackTrace();
}
}
use of org.apache.rocketmq.client.consumer.DefaultMQPushConsumer in project rocketmq-externals by apache.
the class JmsClientIT method testConfigInURI.
@Test
public void testConfigInURI() throws Exception {
JmsBaseConnectionFactory connectionFactory = new JmsBaseConnectionFactory(new URI(String.format("rocketmq://xxx?%s=%s&%s=%s&%s=%s&%s=%s&%s=%s&%s=%s", CommonConstant.PRODUCERID, producerId, CommonConstant.CONSUMERID, consumerId, CommonConstant.NAMESERVER, nameServer, CommonConstant.CONSUME_THREAD_NUMS, consumeThreadNums, CommonConstant.SEND_TIMEOUT_MILLIS, 10 * 1000, CommonConstant.INSTANCE_NAME, "JMS_TEST")));
Connection connection = connectionFactory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
connection.start();
try {
Destination destination = session.createTopic(topic + ":" + messageType);
session.createConsumer(destination);
session.createProducer(destination);
DefaultMQPushConsumer rmqPushConsumer = (DefaultMQPushConsumer) getRMQPushConsumerExt(consumerId).getConsumer();
Assert.assertNotNull(rmqPushConsumer);
Assert.assertEquals(consumerId, rmqPushConsumer.getConsumerGroup());
Assert.assertEquals("JMS_TEST", rmqPushConsumer.getInstanceName());
Assert.assertEquals(consumeThreadNums, rmqPushConsumer.getConsumeThreadMax());
Assert.assertEquals(consumeThreadNums, rmqPushConsumer.getConsumeThreadMin());
Assert.assertEquals(nameServer, rmqPushConsumer.getNamesrvAddr());
DefaultMQProducer mqProducer = (DefaultMQProducer) JmsTestUtil.getMQProducer(producerId);
Assert.assertNotNull(mqProducer);
Assert.assertEquals(producerId, mqProducer.getProducerGroup());
Assert.assertEquals("JMS_TEST", mqProducer.getInstanceName());
Assert.assertEquals(10 * 1000, mqProducer.getSendMsgTimeout());
Assert.assertEquals(nameServer, mqProducer.getNamesrvAddr());
Thread.sleep(2000);
} finally {
connection.close();
}
}
use of org.apache.rocketmq.client.consumer.DefaultMQPushConsumer in project rocketmq-externals by apache.
the class DefaultRocketMQListenerContainer method initRocketMQPushConsumer.
private void initRocketMQPushConsumer() throws MQClientException {
Assert.notNull(rocketMQListener, "Property 'rocketMQListener' is required");
Assert.notNull(consumerGroup, "Property 'consumerGroup' is required");
Assert.notNull(nameServer, "Property 'nameServer' is required");
Assert.notNull(topic, "Property 'topic' is required");
consumer = new DefaultMQPushConsumer(consumerGroup);
consumer.setNamesrvAddr(nameServer);
consumer.setConsumeThreadMax(consumeThreadMax);
if (consumeThreadMax < consumer.getConsumeThreadMin()) {
consumer.setConsumeThreadMin(consumeThreadMax);
}
consumer.setMessageModel(messageModel);
switch(selectorType) {
case TAG:
consumer.subscribe(topic, selectorExpress);
break;
case SQL92:
consumer.subscribe(topic, MessageSelector.bySql(selectorExpress));
break;
default:
throw new IllegalArgumentException("Property 'selectorType' was wrong.");
}
switch(consumeMode) {
case ORDERLY:
consumer.setMessageListener(new DefaultMessageListenerOrderly());
break;
case CONCURRENTLY:
consumer.setMessageListener(new DefaultMessageListenerConcurrently());
break;
default:
throw new IllegalArgumentException("Property 'consumeMode' was wrong.");
}
// provide an entryway to custom setting RocketMQ consumer
if (rocketMQListener instanceof RocketMQPushConsumerLifecycleListener) {
((RocketMQPushConsumerLifecycleListener) rocketMQListener).prepareStart(consumer);
}
}
Aggregations