本文整理汇总了Java中org.apache.rocketmq.client.consumer.DefaultMQPushConsumer.setMessageListener方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultMQPushConsumer.setMessageListener方法的具体用法?Java DefaultMQPushConsumer.setMessageListener怎么用?Java DefaultMQPushConsumer.setMessageListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.rocketmq.client.consumer.DefaultMQPushConsumer
的用法示例。
在下文中一共展示了DefaultMQPushConsumer.setMessageListener方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initRocketMQPushConsumer
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
private void initRocketMQPushConsumer() throws MQClientException {
Assert.notNull(getConsumerGroup(), "Property 'consumerGroup' is required");
Assert.notEmpty(subscribeTopicTags(), "subscribeTopicTags method can't be empty");
consumer = new DefaultMQPushConsumer(getConsumerGroup());
if (consumeThreadMax != null) {
consumer.setConsumeThreadMax(consumeThreadMax);
}
if (consumeThreadMax != null && consumeThreadMax < consumer.getConsumeThreadMin()) {
consumer.setConsumeThreadMin(consumeThreadMax);
}
consumer.setConsumeFromWhere(consumeFromWhere);
consumer.setMessageModel(messageModel);
switch (consumeMode) {
case Orderly:
consumer.setMessageListener(new DefaultMessageListenerOrderly());
break;
case CONCURRENTLY:
consumer.setMessageListener(new DefaultMessageListenerConcurrently());
break;
default:
throw new IllegalArgumentException("Property 'consumeMode' was wrong.");
}
}
示例2: test
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
@Test
public void test() throws Exception {
RocketmqMessageConsumerListener messageConsumerListener = new RocketmqMessageConsumerListener();
messageConsumerListener.setModel("MODEL_1");
messageConsumerListener.setBatch("NON_BATCH");
messageConsumerListener.setMessageDecoder(new RocketmqMessageDecoderDemo());
messageConsumerListener.setConsumer(new MessageConsumer());
DefaultMQPushConsumer defaultMQPushConsumer = new DefaultMQPushConsumer();
defaultMQPushConsumer.setNamesrvAddr("localhost:9876");
defaultMQPushConsumer.setConsumerGroup("contest");
defaultMQPushConsumer.subscribe("QUEUE_TEST", "*");
defaultMQPushConsumer.setMessageListener(messageConsumerListener.getMessageListener());
defaultMQPushConsumer.start();
}
示例3: create
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
public void create() {
consumer = new DefaultMQPushConsumer(consumerGroup);
consumer.setInstanceName(RandomUtil.getStringByUUID());
consumer.setNamesrvAddr(nsAddr);
try {
consumer.subscribe(topic, subExpression);
} catch (MQClientException e) {
logger.error("consumer subscribe failed!");
e.printStackTrace();
}
consumer.setMessageListener(listner);
}
示例4: create
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
public void create(boolean useTLS) {
consumer = new DefaultMQPushConsumer(consumerGroup);
consumer.setInstanceName(RandomUtil.getStringByUUID());
consumer.setNamesrvAddr(nsAddr);
try {
consumer.subscribe(topic, subExpression);
} catch (MQClientException e) {
logger.error("consumer subscribe failed!");
e.printStackTrace();
}
consumer.setMessageListener(listener);
consumer.setUseTLS(useTLS);
}
示例5: initRocketMQPushConsumer
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
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.setPullThresholdForTopic(pullThresholdForTopic);
consumer.setPullThresholdSizeForTopic(pullThresholdSizeForTopic);
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);
}
}
开发者ID:QianmiOpen,项目名称:spring-boot-starter-rocketmq,代码行数:47,代码来源:DefaultRocketMQListenerContainer.java