当前位置: 首页>>代码示例>>Java>>正文


Java ConsumeFromWhere类代码示例

本文整理汇总了Java中com.alibaba.rocketmq.common.consumer.ConsumeFromWhere的典型用法代码示例。如果您正苦于以下问题:Java ConsumeFromWhere类的具体用法?Java ConsumeFromWhere怎么用?Java ConsumeFromWhere使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ConsumeFromWhere类属于com.alibaba.rocketmq.common.consumer包,在下文中一共展示了ConsumeFromWhere类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import com.alibaba.rocketmq.common.consumer.ConsumeFromWhere; //导入依赖的package包/类
public static void main(String[] args){
	DefaultMQPushConsumer consumer =
			new DefaultMQPushConsumer("PushConsumer");
	consumer.setNamesrvAddr("127.0.0.1:9876");
	try {
		//订阅PushTopic下Tag为push的消息
		consumer.subscribe("PushTopic", "push");
		//程序第一次启动从消息队列头取数据
		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 (Exception e) {
		e.printStackTrace();
	}
}
 
开发者ID:youngMen1,项目名称:-Spring-SpringMVC-Mybatis-,代码行数:27,代码来源:Consumer.java

示例2: main

import com.alibaba.rocketmq.common.consumer.ConsumeFromWhere; //导入依赖的package包/类
public static void main(String[] args) throws InterruptedException, MQClientException {
    DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("please_rename_unique_group_name_4");

    consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);

    consumer.subscribe("TopicTest", "*");

    consumer.registerMessageListener(new MessageListenerConcurrently() {

        @Override
        public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs,
                ConsumeConcurrentlyContext context) {
            System.out.println(Thread.currentThread().getName() + " Receive New Messages: " + msgs);
            return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
        }
    });

    consumer.start();

    System.out.println("Consumer Started.");
}
 
开发者ID:y123456yz,项目名称:reading-and-annotate-rocketmq-3.4.6,代码行数:22,代码来源:Consumer.java

示例3: consume

import com.alibaba.rocketmq.common.consumer.ConsumeFromWhere; //导入依赖的package包/类
public void consume(String topic, String subExpression) throws MQClientException {

        consumer.subscribe(topic, "*");
//        consumer.subscribe(topic, "TagA || TagB");
//        consumer.subscribe(topic, "*");

        consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);

        consumer.registerMessageListener(new MessageListenerConcurrently() {

            @Override
            public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext context) {

                for(MessageExt msg : msgs) {
                    if (msg.getTags() != null && msg.getTags().equals("TagA")) {
                        // 执行TagA的消费
                    }
                    else if (msg.getTags() != null && msg.getTags().equals("TagB")) {
                        // 执行TagB的消费
                    }
                }
                return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
            }
        });

    }
 
开发者ID:TFdream,项目名称:mq-in-action,代码行数:27,代码来源:MqPushConsumer.java

示例4: testBroadcastConsumer

import com.alibaba.rocketmq.common.consumer.ConsumeFromWhere; //导入依赖的package包/类
@Before
public void testBroadcastConsumer() throws Exception {
    DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("example_group_name");

    consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);

    // set to broadcast mode
    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");
}
 
开发者ID:dzh,项目名称:coca,代码行数:24,代码来源:TestBroadcastProducer.java

示例5: registerConsumer

import com.alibaba.rocketmq.common.consumer.ConsumeFromWhere; //导入依赖的package包/类
public boolean registerConsumer(final String group, final ClientChannelInfo clientChannelInfo,
        ConsumeType consumeType, MessageModel messageModel, ConsumeFromWhere consumeFromWhere,
        final Set<SubscriptionData> subList) {

    ConsumerGroupInfo consumerGroupInfo = this.consumerTable.get(group);
    if (null == consumerGroupInfo) {
        ConsumerGroupInfo tmp = new ConsumerGroupInfo(group, consumeType, messageModel, consumeFromWhere);
        ConsumerGroupInfo prev = this.consumerTable.putIfAbsent(group, tmp);
        consumerGroupInfo = prev != null ? prev : tmp;
    }

    boolean r1 =
            consumerGroupInfo.updateChannel(clientChannelInfo, consumeType, messageModel,
                consumeFromWhere);

    boolean r2 = consumerGroupInfo.updateSubscription(subList);

    if (r1 || r2) {
        this.consumerIdsChangeListener.consumerIdsChanged(group, consumerGroupInfo.getAllChannel());
    }

    return r1 || r2;
}
 
开发者ID:medusar,项目名称:rocketmq-commet,代码行数:24,代码来源:ConsumerManager.java

示例6: RocketMQTracerConsumer

import com.alibaba.rocketmq.common.consumer.ConsumeFromWhere; //导入依赖的package包/类
public RocketMQTracerConsumer() throws MQClientException {
	this.consumer = new DefaultMQPushConsumer("MonitorConsumer");
	this.consumer.setNamesrvAddr("127.0.0.1:9876");
	this.consumer.subscribe("dst_span_topic", "*");

	this.consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
	this.consumer.registerMessageListener(new MessageListenerConcurrently() {
		@Override
		public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext context) {
			Map _r = new HashMap<>();
			for(MessageExt mess : msgs){
				JSONArray array = (JSONArray)JSONArray.parse(mess.getBody());
				for(int i = 0;i<array.size();i++ ){
					_r = (Map)array.get(i);
					_r.put("index_name", "application");
					_r.put("type_name", "monitor");
					storage.doStorage(_r);
				}
			}
			
			return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
		}
	});

	this.consumer.start();
}
 
开发者ID:O2O-Market,项目名称:Market-monitor,代码行数:27,代码来源:RocketMQTracerConsumer.java

示例7: pushConsumerFromLastOffset

import com.alibaba.rocketmq.common.consumer.ConsumeFromWhere; //导入依赖的package包/类
@Test
public void pushConsumerFromLastOffset() throws MQClientException {
    consumer.setMessageModel(MessageModel.CLUSTERING);
    consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_LAST_OFFSET);
    MessageListener listener = createMessageListener();
    consumer.registerMessageListener(listener);

    consumer.start();
    System.out.println("Consumer Started.");
    try {
        System.in.read();
    }
    catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:diwayou,项目名称:rocketmq-all-trans,代码行数:17,代码来源:PushConsumerTest.java

示例8: pushConsumerFromMinOffset

import com.alibaba.rocketmq.common.consumer.ConsumeFromWhere; //导入依赖的package包/类
@Test
public void pushConsumerFromMinOffset() throws MQClientException {
    consumer.setMessageModel(MessageModel.CLUSTERING);
    consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
    MessageListener listener = createMessageListener();
    consumer.registerMessageListener(listener);

    consumer.start();
    System.out.println("Consumer Started.");
    try {
        System.in.read();
    }
    catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:diwayou,项目名称:rocketmq-all-trans,代码行数:17,代码来源:PushConsumerTest.java

示例9: pushConsumerFromLastOffset

import com.alibaba.rocketmq.common.consumer.ConsumeFromWhere; //导入依赖的package包/类
@Test
public void pushConsumerFromLastOffset() throws MQClientException {
    consumer.setMessageModel(MessageModel.CLUSTERING);
    consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_LAST_OFFSET);
    MessageListener listener = getRollBackMessageListener();
    consumer.registerMessageListener(listener);

    consumer.start();
    System.out.println("Consumer Started.");
    try {
        System.in.read();
    }
    catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:diwayou,项目名称:rocketmq-all-trans,代码行数:17,代码来源:PushConsumerTest.java

示例10: pushConsumerWithAutoCommitFromLastOffset

import com.alibaba.rocketmq.common.consumer.ConsumeFromWhere; //导入依赖的package包/类
@Test
public void pushConsumerWithAutoCommitFromLastOffset() throws MQClientException {
    consumer.setMessageModel(MessageModel.CLUSTERING);
    consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_LAST_OFFSET);
    MessageListener listener = getAutoCommitMessageListener();
    consumer.registerMessageListener(listener);

    consumer.start();
    System.out.println("Consumer Started.");
    try {
        System.in.read();
    }
    catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:diwayou,项目名称:rocketmq-all-trans,代码行数:17,代码来源:PushConsumerTest.java

示例11: pushConsumerWithAutoCommitFromMinOffset

import com.alibaba.rocketmq.common.consumer.ConsumeFromWhere; //导入依赖的package包/类
@Test
public void pushConsumerWithAutoCommitFromMinOffset() throws MQClientException {
    consumer.setMessageModel(MessageModel.CLUSTERING);
    consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
    MessageListener listener = getAutoCommitMessageListener();
    consumer.registerMessageListener(listener);

    consumer.start();
    System.out.println("Consumer Started.");
    try {
        System.in.read();
    }
    catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:diwayou,项目名称:rocketmq-all-trans,代码行数:17,代码来源:PushConsumerTest.java

示例12: createConsumer

import com.alibaba.rocketmq.common.consumer.ConsumeFromWhere; //导入依赖的package包/类
private static MQPushConsumer createConsumer(String nsAddr, String... topics) throws MQClientException {
    DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(consumerGroup);
    consumer.setInstanceName("unit_consumer_" + System.nanoTime());
    consumer.setNamesrvAddr(nsAddr);
    for (String topic : topics) {
        consumer.subscribe(topic, "*");
    }

    consumer.setMessageModel(MessageModel.CLUSTERING);
    consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_LAST_OFFSET);
    MessageListener listener = createMessageListener();
    consumer.registerMessageListener(listener);
    consumer.setConsumeThreadMax(1);
    consumer.setConsumeThreadMin(1);

    consumer.start();
    return consumer;
}
 
开发者ID:diwayou,项目名称:rocketmq-all-trans,代码行数:19,代码来源:UnitOrderTest.java

示例13: main

import com.alibaba.rocketmq.common.consumer.ConsumeFromWhere; //导入依赖的package包/类
public static void main(String[] args) throws InterruptedException, MQClientException {
    DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("please_rename_unique_group_name_4");
    /**
     * 设置Consumer第一次启动是从队列头部开始消费还是队列尾部开始消费<br>
     * 如果非第一次启动,那么按照上次消费的位置继续消费
     */
    consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);

    consumer.subscribe("TopicTest", "*");

    consumer.registerMessageListener(new MessageListenerConcurrently() {

        @Override
        public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs,
                ConsumeConcurrentlyContext context) {
            System.out.println(Thread.currentThread().getName() + " Receive New Messages: " + msgs);
            return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
        }
    });

    consumer.start();

    System.out.println("Consumer Started.");
}
 
开发者ID:diwayou,项目名称:rocketmq-all-trans,代码行数:25,代码来源:Consumer.java

示例14: updateChannel

import com.alibaba.rocketmq.common.consumer.ConsumeFromWhere; //导入依赖的package包/类
/**
 * 返回值表示是否发生变更
 */
public boolean updateChannel(final ClientChannelInfo clientChannelInfo, ConsumeType consumeType,
        MessageModel messageModel, ConsumeFromWhere consumeFromWhere) {
    boolean updated = false;
    this.consumeType = consumeType;
    this.messageModel = messageModel;
    this.consumeFromWhere = consumeFromWhere;

    ClientChannelInfo info = this.channelInfoTable.get(clientChannelInfo.getChannel());
    if (null == info) {
        ClientChannelInfo prev =
                this.channelInfoTable.put(clientChannelInfo.getChannel(), clientChannelInfo);
        if (null == prev) {
            log.info("new consumer connected, group: {} {} {} channel: {}", this.groupName, consumeType,
                messageModel, clientChannelInfo.toString());
            updated = true;
        }

        info = clientChannelInfo;
    }

    this.lastUpdateTimestamp = System.currentTimeMillis();
    info.setLastUpdateTimestamp(this.lastUpdateTimestamp);

    return updated;
}
 
开发者ID:diwayou,项目名称:rocketmq-all-trans,代码行数:29,代码来源:ConsumerGroupInfo.java

示例15: registerConsumer

import com.alibaba.rocketmq.common.consumer.ConsumeFromWhere; //导入依赖的package包/类
/**
 * 返回是否有变化
 */
public boolean registerConsumer(final String group, final ClientChannelInfo clientChannelInfo,
        ConsumeType consumeType, MessageModel messageModel, ConsumeFromWhere consumeFromWhere,
        final Set<SubscriptionData> subList) {
    ConsumerGroupInfo consumerGroupInfo = this.consumerTable.get(group);
    if (null == consumerGroupInfo) {
        ConsumerGroupInfo tmp = new ConsumerGroupInfo(group, consumeType, messageModel, consumeFromWhere);
        ConsumerGroupInfo prev = this.consumerTable.putIfAbsent(group, tmp);
        consumerGroupInfo = prev != null ? prev : tmp;
    }

    boolean r1 =
            consumerGroupInfo.updateChannel(clientChannelInfo, consumeType, messageModel,
                consumeFromWhere);
    boolean r2 = consumerGroupInfo.updateSubscription(subList);

    if (r1 || r2) {
        this.consumerIdsChangeListener.consumerIdsChanged(group, consumerGroupInfo.getAllChannel());
    }

    return r1 || r2;
}
 
开发者ID:diwayou,项目名称:rocketmq-all-trans,代码行数:25,代码来源:ConsumerManager.java


注:本文中的com.alibaba.rocketmq.common.consumer.ConsumeFromWhere类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。