本文整理汇总了Java中org.apache.rocketmq.client.consumer.DefaultMQPushConsumer.setMessageModel方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultMQPushConsumer.setMessageModel方法的具体用法?Java DefaultMQPushConsumer.setMessageModel怎么用?Java DefaultMQPushConsumer.setMessageModel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.rocketmq.client.consumer.DefaultMQPushConsumer
的用法示例。
在下文中一共展示了DefaultMQPushConsumer.setMessageModel方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: receiveBroadcastMessage
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
public void receiveBroadcastMessage(){
DefaultMQPushConsumer consumer=new DefaultMQPushConsumer(RocketMQConfiguration.ROCKETMQ_GROUP);
consumer.setNamesrvAddr(RocketMQConfiguration.ROCKETMQ_NAMESRV);
consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
consumer.setMessageModel(MessageModel.BROADCASTING);
try {
consumer.subscribe(RocketMQConfiguration.ROCKETMQ_TOPIC,"*");
consumer.registerMessageListener(new MessageListenerConcurrently() {
@Override
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext consumeConcurrentlyContext) {
System.out.printf(Thread.currentThread().getName() + " Receive New Messages: " + msgs + "%n");
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
});
consumer.start();
} catch (MQClientException e) {
e.printStackTrace();
}
}
示例2: main
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException, MQClientException {
DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("please_rename_unique_group_name_1");
consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
consumer.setMessageModel(MessageModel.BROADCASTING);
consumer.subscribe("TopicTest", "TagA || TagC || TagD");
consumer.registerMessageListener(new MessageListenerConcurrently() {
@Override
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs,
ConsumeConcurrentlyContext context) {
System.out.printf(Thread.currentThread().getName() + " Receive New Messages: " + msgs + "%n");
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
});
consumer.start();
System.out.printf("Broadcast Consumer Started.%n");
}
示例3: 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.");
}
}
示例4: main
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException, MQClientException {
DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("broadcast_consumer_group");
consumer.setNamesrvAddr("127.0.0.1:9876");
consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
consumer.setMessageModel(MessageModel.BROADCASTING);
consumer.subscribe("TopicTest", "TagA || TagC || TagD");
consumer.registerMessageListener(new MessageListenerConcurrently() {
@Override
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs,
ConsumeConcurrentlyContext context) {
System.out.printf(Thread.currentThread().getName() + " Receive New Messages: " + msgs + "%n");
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
});
consumer.start();
System.out.printf("Broadcast Consumer Started.%n");
}
示例5: main
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException, MQClientException {
DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("please_rename_unique_group_name_1");
consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
consumer.setMessageModel(MessageModel.BROADCASTING);
consumer.subscribe("TopicTest", "TagA || TagC || TagD");
consumer.registerMessageListener(new MessageListenerConcurrently() {
@Override
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs,
ConsumeConcurrentlyContext context) {
System.out.printf("%s Receive New Messages: %s %n", Thread.currentThread().getName(), msgs);
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
});
consumer.start();
System.out.printf("Broadcast Consumer Started.%n");
}
示例6: main
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException, MQClientException {
//创建Push 模式的consumer 客户端门面类,指定ConsumerGroup
DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("CID_JODIE_1");
//指定订阅的topic以及订阅标志
consumer.subscribe("Jodie_topic_1023", "*");
//指定消费位置,这里设置从消息的最新未消费的位移开始
consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_LAST_OFFSET);
//设置消息消费模式,这里为集群模式,即点对点通讯
consumer.setMessageModel(MessageModel.CLUSTERING);
//设置集群管理nameser的地址,集群间使用“;”分开
consumer.setNamesrvAddr("192.168.212.17:9876;192.168.212.18:9876;");
//注册客户端消费逻辑,这里为并发消费
consumer.registerMessageListener(new MessageListenerConcurrently() {
@Override
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext context) {
System.out.printf(Thread.currentThread().getName() + " Receive New Messages: " + msgs + "%n");
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
});
//启动消费客户端
consumer.start();
System.out.printf("Consumer Started.%n");
}
示例7: 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