本文整理汇总了Java中org.apache.rocketmq.client.consumer.DefaultMQPushConsumer.setConsumeFromWhere方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultMQPushConsumer.setConsumeFromWhere方法的具体用法?Java DefaultMQPushConsumer.setConsumeFromWhere怎么用?Java DefaultMQPushConsumer.setConsumeFromWhere使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.rocketmq.client.consumer.DefaultMQPushConsumer
的用法示例。
在下文中一共展示了DefaultMQPushConsumer.setConsumeFromWhere方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: receiveTransactionMessage
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
/**
* 接收消息
*/
public void receiveTransactionMessage() {
DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(RocketMQConfiguration.ROCKETMQ_GROUP);
consumer.setNamesrvAddr(RocketMQConfiguration.ROCKETMQ_NAMESRV);
consumer.setVipChannelEnabled(false);
consumer.setConsumeThreadMax(20);
consumer.setConsumeThreadMin(10);
try {
consumer.subscribe(RocketMQConfiguration.ROCKETMQ_TOPIC, "transaction");
//程序第一次启动从消息队列头取数据
consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
consumer.registerMessageListener(
new MessageListenerConcurrently() {
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> list, ConsumeConcurrentlyContext Context) {
Message msg = list.get(0);
System.out.println(msg.toString());
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
}
);
consumer.start();
} catch (MQClientException e) {
e.printStackTrace();
}
}
示例2: receiveMessage
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
/**
* 接收消息
*/
public void receiveMessage(){
DefaultMQPushConsumer consumer =new DefaultMQPushConsumer(RocketMQConfiguration.ROCKETMQ_GROUP);
consumer.setNamesrvAddr(RocketMQConfiguration.ROCKETMQ_NAMESRV);
consumer.setVipChannelEnabled(false);
try {
consumer.subscribe(RocketMQConfiguration.ROCKETMQ_TOPIC, "schedule");
//程序第一次启动从消息队列头取数据
consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
consumer.registerMessageListener(
new MessageListenerConcurrently() {
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> list,ConsumeConcurrentlyContext Context) {
Message msg = list.get(0);
System.out.println(msg.toString());
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
}
);
consumer.start();
} catch (MQClientException e) {
e.printStackTrace();
}
}
示例3: receiveFilterMessage
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
/**
* 接收消息
*/
public void receiveFilterMessage(){
DefaultMQPushConsumer consumer =new DefaultMQPushConsumer(RocketMQConfiguration.ROCKETMQ_GROUP);
consumer.setNamesrvAddr(RocketMQConfiguration.ROCKETMQ_NAMESRV);
consumer.setVipChannelEnabled(false);
try {
consumer.subscribe(RocketMQConfiguration.ROCKETMQ_TOPIC, MessageSelector.bySql("a between 5 and 8"));
//程序第一次启动从消息队列头取数据
consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
consumer.registerMessageListener(
new MessageListenerConcurrently() {
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> list, ConsumeConcurrentlyContext Context) {
Message msg = list.get(0);
System.out.println(msg.toString());
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
}
);
consumer.start();
} catch (MQClientException e) {
e.printStackTrace();
}
}
示例4: 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");
}
示例5: 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.");
}
}
示例6: main
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException, MQClientException {
DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("CID_JODIE_1");
consumer.subscribe("Jodie_topic_1023", "*");
consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
//wrong time format 2017_0422_221800
consumer.setConsumeTimestamp("20170422221800");
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: 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");
}
示例8: main
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
public static void main(String[] args) throws MQClientException {
DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("order_message_consumer_group");
consumer.setNamesrvAddr("127.0.0.1:9876");
consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
consumer.subscribe("TopicTest", "TagA || TagC || TagD");
// 顺序消费特点:不会有两个消费者共同消费任一队列,且当消费者数量小于队列数时,消费者会消费多个队列
consumer.registerMessageListener(new MessageListenerOrderly() {
@Override
public ConsumeOrderlyStatus consumeMessage(List<MessageExt> msgs, ConsumeOrderlyContext context) {
//context.setAutoCommit(false);
System.out.printf(System.currentTimeMillis() + "," + Thread.currentThread().getName() + " Receive New Messages: " + msgs + "%n");
return ConsumeOrderlyStatus.SUCCESS;
}
});
consumer.start();
System.out.printf("Consumer Started.%n");
}
示例9: main
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException, MQClientException {
DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("push_consumer_group");
consumer.setNamesrvAddr("127.0.0.1:9876");
consumer.subscribe("TopicTest", "*");
consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
//wrong time format 2017_0422_221800
consumer.setConsumeTimestamp("20170422221800");
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");
}
示例10: testConsumer
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
@Test
public void testConsumer() {
DefaultMQPushConsumer consumer =
new DefaultMQPushConsumer("PushConsumer");
consumer.setNamesrvAddr("192.168.146.109:9876");
try {
//订阅PushTopic下Tag为push的消息
consumer.subscribe("PushTopic", "push");
//程序第一次启动从消息队列头取数据
consumer.setConsumeFromWhere(
ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
consumer.registerMessageListener(
(MessageListenerConcurrently) (list, Context) -> {
Message msg = list.get(0);
System.out.println(msg.toString());
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
);
consumer.start();
} catch (Exception e) {
e.printStackTrace();
}
}
示例11: 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");
}
示例12: main
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException, MQClientException {
DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("CID_JODIE_1");
consumer.subscribe("Jodie_topic_1023", "*");
consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
//wrong time format 2017_0422_221800
consumer.setConsumeTimestamp("20170422221800");
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("Consumer Started.%n");
}
示例13: receiveOrderMessage
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
public void receiveOrderMessage(){
DefaultMQPushConsumer consumer=new DefaultMQPushConsumer(RocketMQConfiguration.ROCKETMQ_GROUP);
consumer.setNamesrvAddr(RocketMQConfiguration.ROCKETMQ_NAMESRV);
consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
try {
consumer.subscribe(RocketMQConfiguration.ROCKETMQ_TOPIC,"*");
//监听消息接受
consumer.registerMessageListener(new MessageListenerOrderly() {
AtomicLong consumeTimes = new AtomicLong(0);
@Override
public ConsumeOrderlyStatus consumeMessage(List<MessageExt> msgs, ConsumeOrderlyContext consumeOrderlyContext) {
consumeOrderlyContext.setAutoCommit(false);
System.out.printf(Thread.currentThread().getName() + " Receive New Messages: " + new String(msgs.get(0).getBody()) + "%n");
System.out.println(consumeTimes.incrementAndGet());
if ((this.consumeTimes.get() % 2) == 0) {
return ConsumeOrderlyStatus.SUCCESS;
} else if ((this.consumeTimes.get() % 3) == 0) {
return ConsumeOrderlyStatus.ROLLBACK;
} else if ((this.consumeTimes.get() % 4) == 0) {
return ConsumeOrderlyStatus.COMMIT;
} else if ((this.consumeTimes.get() % 5) == 0) {
consumeOrderlyContext.setSuspendCurrentQueueTimeMillis(3000);
return ConsumeOrderlyStatus.SUSPEND_CURRENT_QUEUE_A_MOMENT;
}
return ConsumeOrderlyStatus.SUCCESS;
}
});
consumer.start();
} catch (MQClientException e) {
e.printStackTrace();
}
}
示例14: 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");
}
示例15: main
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
public static void main(String[] args) throws MQClientException {
DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("please_rename_unique_group_name_3");
consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
consumer.subscribe("TopicTest", "TagA || TagC || TagD");
consumer.registerMessageListener(new MessageListenerOrderly() {
AtomicLong consumeTimes = new AtomicLong(0);
@Override
public ConsumeOrderlyStatus consumeMessage(List<MessageExt> msgs, ConsumeOrderlyContext context) {
context.setAutoCommit(false);
System.out.printf(Thread.currentThread().getName() + " Receive New Messages: " + msgs + "%n");
this.consumeTimes.incrementAndGet();
if ((this.consumeTimes.get() % 2) == 0) {
return ConsumeOrderlyStatus.SUCCESS;
} else if ((this.consumeTimes.get() % 3) == 0) {
return ConsumeOrderlyStatus.ROLLBACK;
} else if ((this.consumeTimes.get() % 4) == 0) {
return ConsumeOrderlyStatus.COMMIT;
} else if ((this.consumeTimes.get() % 5) == 0) {
context.setSuspendCurrentQueueTimeMillis(3000);
return ConsumeOrderlyStatus.SUSPEND_CURRENT_QUEUE_A_MOMENT;
}
return ConsumeOrderlyStatus.SUCCESS;
}
});
consumer.start();
System.out.printf("Consumer Started.%n");
}