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


Java PullResult.getPullStatus方法代码示例

本文整理汇总了Java中com.alibaba.rocketmq.client.consumer.PullResult.getPullStatus方法的典型用法代码示例。如果您正苦于以下问题:Java PullResult.getPullStatus方法的具体用法?Java PullResult.getPullStatus怎么用?Java PullResult.getPullStatus使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.alibaba.rocketmq.client.consumer.PullResult的用法示例。


在下文中一共展示了PullResult.getPullStatus方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: firePullResult

import com.alibaba.rocketmq.client.consumer.PullResult; //导入方法依赖的package包/类
private void firePullResult(PullResult pullResult) {
    switch (pullResult.getPullStatus()) {
    case FOUND:
        for (MessageExt mex : pullResult.getMsgFoundList()) {
            System.out.println(mex);
        }
        break;
    case NO_MATCHED_MSG:
        break;
    case NO_NEW_MSG:
        break;
    case OFFSET_ILLEGAL:
        break;
    default:
        break;
    }
}
 
开发者ID:diwayou,项目名称:rocketmq-all-trans,代码行数:18,代码来源:PullConsumerTest.java

示例2: main

import com.alibaba.rocketmq.client.consumer.PullResult; //导入方法依赖的package包/类
public static void main(String[] args) throws MQClientException {
    DefaultMQPullConsumer consumer = new DefaultMQPullConsumer("please_rename_unique_group_name_5");

    consumer.start();

    Set<MessageQueue> mqs = consumer.fetchSubscribeMessageQueues("TopicTest1");
    for (MessageQueue mq : mqs) {
        System.out.println("Consume from the queue: " + mq);
        SINGLE_MQ: while (true) {
            try {
                PullResult pullResult =
                        consumer.pullBlockIfNotFound(mq, null, getMessageQueueOffset(mq), 32);
                System.out.println(pullResult);
                putMessageQueueOffset(mq, pullResult.getNextBeginOffset());
                switch (pullResult.getPullStatus()) {
                case FOUND:
                    break;
                case NO_MATCHED_MSG:
                    break;
                case NO_NEW_MSG:
                    break SINGLE_MQ;
                case OFFSET_ILLEGAL:
                    break;
                default:
                    break;
                }
            }
            catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    consumer.shutdown();
}
 
开发者ID:y123456yz,项目名称:reading-and-annotate-rocketmq-3.4.6,代码行数:36,代码来源:PullConsumer.java

示例3: pull

import com.alibaba.rocketmq.client.consumer.PullResult; //导入方法依赖的package包/类
public void pull() throws Exception {

        //获取订阅topic的queue
        Set<MessageQueue> mqs = consumer.fetchSubscribeMessageQueues("TopicTest1");
        for (MessageQueue mq : mqs) {
            System.out.println("Consume from the queue: " + mq);
            SINGLE_MQ:
            while (true) {
                try {//阻塞的拉去消息,中止时间默认20s
                    PullResult pullResult =
                            consumer.pullBlockIfNotFound(mq, null, getMessageQueueOffset(mq), 32);
                    System.out.println(Thread.currentThread().getName()+new Date()+""+pullResult);
                    putMessageQueueOffset(mq, pullResult.getNextBeginOffset());
                    switch (pullResult.getPullStatus()) {
                        case FOUND://pullSataus
                            break;
                        case NO_MATCHED_MSG:
                            break;
                        case NO_NEW_MSG:
                            break SINGLE_MQ;
                        case OFFSET_ILLEGAL:
                            break;
                        default:
                            break;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
 
开发者ID:TFdream,项目名称:mq-in-action,代码行数:32,代码来源:MqPullConsumer.java

示例4: main

import com.alibaba.rocketmq.client.consumer.PullResult; //导入方法依赖的package包/类
public static void main(String[] args) throws MQClientException {
    DefaultMQPullConsumer consumer = new DefaultMQPullConsumer("please_rename_unique_group_name_5");

    consumer.start();

    Set<MessageQueue> mqs = consumer.fetchSubscribeMessageQueues("TopicTest");
    for (MessageQueue mq : mqs) {
        System.out.println("Consume from the queue: " + mq);
        SINGLE_MQ: while (true) {
            try {
                PullResult pullResult =
                        consumer.pullBlockIfNotFound(mq, null, getMessageQueueOffset(mq), 32);
                System.out.println(pullResult);
                putMessageQueueOffset(mq, pullResult.getNextBeginOffset());
                switch (pullResult.getPullStatus()) {
                case FOUND:
                    // TODO
                    break;
                case NO_MATCHED_MSG:
                    break;
                case NO_NEW_MSG:
                    break SINGLE_MQ;
                case OFFSET_ILLEGAL:
                    break;
                default:
                    break;
                }
            }
            catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

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

示例5: execute

import com.alibaba.rocketmq.client.consumer.PullResult; //导入方法依赖的package包/类
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
    DefaultMQPullConsumer defaultMQPullConsumer = new DefaultMQPullConsumer(MixAll.TOOLS_CONSUMER_GROUP);

    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
    defaultMQPullConsumer.setInstanceName(Long.toString(System.currentTimeMillis()));

    try {
        //解析 sh mqadmin  queryMsgByOffset 命令携带的各种参数信息
        String topic = commandLine.getOptionValue('t').trim();
        String brokerName = commandLine.getOptionValue('b').trim();
        String queueId = commandLine.getOptionValue('i').trim();
        String offset = commandLine.getOptionValue('o').trim();

        MessageQueue mq = new MessageQueue();
        mq.setTopic(topic);
        mq.setBrokerName(brokerName);
        mq.setQueueId(Integer.parseInt(queueId));

        defaultMQPullConsumer.start();
        defaultMQAdminExt.start();

        PullResult pullResult = defaultMQPullConsumer.pull(mq, "*", Long.parseLong(offset), 1);
        if (pullResult != null) {
            switch (pullResult.getPullStatus()) {
            case FOUND:
                QueryMsgByIdSubCommand.queryById(defaultMQAdminExt, pullResult.getMsgFoundList().get(0)
                    .getMsgId());
                break;
            case NO_MATCHED_MSG:
            case NO_NEW_MSG:
            case OFFSET_ILLEGAL:
            default:
                break;
            }
        }
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    finally {
        defaultMQPullConsumer.shutdown();
        defaultMQAdminExt.shutdown();
    }
}
 
开发者ID:y123456yz,项目名称:reading-and-annotate-rocketmq-3.4.6,代码行数:47,代码来源:QueryMsgByOffsetSubCommand.java

示例6: computeUndoneMsgs

import com.alibaba.rocketmq.client.consumer.PullResult; //导入方法依赖的package包/类
private void computeUndoneMsgs(final UndoneMsgs undoneMsgs, final ConsumeStats consumeStats) {
    long total = 0;
    long singleMax = 0;
    long delayMax = 0;
    Iterator<Entry<MessageQueue, OffsetWrapper>> it = consumeStats.getOffsetTable().entrySet().iterator();
    while (it.hasNext()) {
        Entry<MessageQueue, OffsetWrapper> next = it.next();
        MessageQueue mq = next.getKey();
        OffsetWrapper ow = next.getValue();
        long diff = ow.getBrokerOffset() - ow.getConsumerOffset();

        if (diff > singleMax) {
            singleMax = diff;
        }

        if (diff > 0) {
            total += diff;
        }

        // Delay
        if (ow.getLastTimestamp() > 0) {
            try {
                long maxOffset = this.defaultMQPullConsumer.maxOffset(mq);
                if (maxOffset > 0) {
                    PullResult pull = this.defaultMQPullConsumer.pull(mq, "*", maxOffset - 1, 1);
                    switch (pull.getPullStatus()) {
                    case FOUND:
                        long delay =
                                pull.getMsgFoundList().get(0).getStoreTimestamp() - ow.getLastTimestamp();
                        if (delay > delayMax) {
                            delayMax = delay;
                        }
                        break;
                    case NO_MATCHED_MSG:
                    case NO_NEW_MSG:
                    case OFFSET_ILLEGAL:
                        break;
                    default:
                        break;
                    }
                }
            }
            catch (Exception e) {
            }
        }
    }

    undoneMsgs.setUndoneMsgsTotal(total);
    undoneMsgs.setUndoneMsgsSingleMQ(singleMax);
    undoneMsgs.setUndoneMsgsDelayTimeMills(delayMax);
}
 
开发者ID:y123456yz,项目名称:reading-and-annotate-rocketmq-3.4.6,代码行数:52,代码来源:MonitorService.java

示例7: execute

import com.alibaba.rocketmq.client.consumer.PullResult; //导入方法依赖的package包/类
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
    DefaultMQPullConsumer defaultMQPullConsumer = new DefaultMQPullConsumer(MixAll.TOOLS_CONSUMER_GROUP);

    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
    defaultMQPullConsumer.setInstanceName(Long.toString(System.currentTimeMillis()));

    try {
        String topic = commandLine.getOptionValue('t').trim();
        String brokerName = commandLine.getOptionValue('b').trim();
        String queueId = commandLine.getOptionValue('i').trim();
        String offset = commandLine.getOptionValue('o').trim();

        MessageQueue mq = new MessageQueue();
        mq.setTopic(topic);
        mq.setBrokerName(brokerName);
        mq.setQueueId(Integer.parseInt(queueId));

        defaultMQPullConsumer.start();
        defaultMQAdminExt.start();

        PullResult pullResult = defaultMQPullConsumer.pull(mq, "*", Long.parseLong(offset), 1);
        if (pullResult != null) {
            switch (pullResult.getPullStatus()) {
            case FOUND:
                QueryMsgByIdSubCommand.queryById(defaultMQAdminExt, pullResult.getMsgFoundList().get(0)
                    .getMsgId());
                break;
            case NO_MATCHED_MSG:
            case NO_NEW_MSG:
            case OFFSET_ILLEGAL:
            default:
                break;
            }
        }
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    finally {
        defaultMQPullConsumer.shutdown();
        defaultMQAdminExt.shutdown();
    }
}
 
开发者ID:medusar,项目名称:rocketmq-commet,代码行数:46,代码来源:QueryMsgByOffsetSubCommand.java

示例8: queryMsgByOffset

import com.alibaba.rocketmq.client.consumer.PullResult; //导入方法依赖的package包/类
@CmdTrace(cmdClazz = QueryMsgByOffsetSubCommand.class)
public Table queryMsgByOffset(String topicName, String brokerName, String queueId, String offset)
        throws Throwable {
    Throwable t = null;
    DefaultMQPullConsumer defaultMQPullConsumer = new DefaultMQPullConsumer(MixAll.TOOLS_CONSUMER_GROUP);

    defaultMQPullConsumer.setInstanceName(Long.toString(System.currentTimeMillis()));

    try {
        MessageQueue mq = new MessageQueue();
        mq.setTopic(topicName);
        mq.setBrokerName(brokerName);
        mq.setQueueId(Integer.parseInt(queueId));

        defaultMQPullConsumer.start();

        PullResult pullResult = defaultMQPullConsumer.pull(mq, "*", Long.parseLong(offset), 1);
        if (pullResult != null) {
            switch (pullResult.getPullStatus()) {
            case FOUND:
                Table table = queryMsgById(pullResult.getMsgFoundList().get(0).getMsgId());
                return table;
            case NO_MATCHED_MSG:
            case NO_NEW_MSG:
            case OFFSET_ILLEGAL:
            default:
                break;
            }
        }
        else {
            throw new IllegalStateException("pullResult is null");
        }
    }
    catch (Throwable e) {
        logger.error(e.getMessage(), e);
        t = e;
    }
    finally {
        defaultMQPullConsumer.shutdown();
    }
    throw t;
}
 
开发者ID:LXLun,项目名称:RocketMQMonitor,代码行数:43,代码来源:MessageService.java

示例9: fetchOneBatch

import com.alibaba.rocketmq.client.consumer.PullResult; //导入方法依赖的package包/类
public List<MessageExt> fetchOneBatch() {
	List<MessageExt> ret = new ArrayList<MessageExt>();
	
	
	String subexpress = metaSpoutConfig.getSubExpress();
	for(Entry<MessageQueue, Long>entry : currentOffsets.entrySet()) {
		MessageQueue mq = entry.getKey();
		Long offset = entry.getValue();
		
		
		int fetchSize = 0;
		int oneFetchSize = Math.min(oneQueueFetchSize, 32);
		
		while(fetchSize < oneQueueFetchSize) {
			
			PullResult pullResult = null;
            try {
                pullResult = consumer.pullBlockIfNotFound(mq, subexpress, offset, oneFetchSize);
                offset = pullResult.getNextBeginOffset();
                PullStatus status = pullResult.getPullStatus();
                if  (status == PullStatus.FOUND) {
                	List<MessageExt> msgList = pullResult.getMsgFoundList();
                    ret.addAll(msgList);
                    fetchSize += msgList.size();
                    continue;
                }else if (status ==  PullStatus.NO_MATCHED_MSG) {
                    continue;
                }else if (status == PullStatus.NO_NEW_MSG ) {
                    break;
                }else if (status == PullStatus.OFFSET_ILLEGAL) {
                    break;
                }else {
                
                    break;
                }
            }
            catch (Exception e) {
                LOG.warn("Failed to fetch messages of " + mq + ":" + offset, e);
                break;
            }
		}
		
		backendOffset.put(mq, offset);
	}
	
	return ret;
}
 
开发者ID:zhangjunfang,项目名称:jstorm-0.9.6.3-,代码行数:48,代码来源:MetaSimpleClient.java

示例10: execute

import com.alibaba.rocketmq.client.consumer.PullResult; //导入方法依赖的package包/类
@Override
public void execute(CommandLine commandLine, Options options) {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt();
    DefaultMQPullConsumer defaultMQPullConsumer = new DefaultMQPullConsumer(MixAll.TOOLS_CONSUMER_GROUP);

    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
    defaultMQPullConsumer.setInstanceName(Long.toString(System.currentTimeMillis()));

    try {
        String topic = commandLine.getOptionValue('t').trim();
        String brokerName = commandLine.getOptionValue('b').trim();
        String queueId = commandLine.getOptionValue('i').trim();
        String offset = commandLine.getOptionValue('o').trim();

        MessageQueue mq = new MessageQueue();
        mq.setTopic(topic);
        mq.setBrokerName(brokerName);
        mq.setQueueId(Integer.parseInt(queueId));

        defaultMQPullConsumer.start();

        PullResult pullResult = defaultMQPullConsumer.pull(mq, "*", Long.parseLong(offset), 1);
        if (pullResult != null) {
            switch (pullResult.getPullStatus()) {
            case FOUND:
                QueryMsgByIdSubCommand.queryById(defaultMQAdminExt, pullResult.getMsgFoundList().get(0)
                    .getMsgId());
                break;
            case NO_MATCHED_MSG:
            case NO_NEW_MSG:
            case OFFSET_ILLEGAL:
            default:
                break;
            }
        }
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    finally {
        defaultMQPullConsumer.shutdown();
        defaultMQAdminExt.shutdown();
    }
}
 
开发者ID:diwayou,项目名称:rocketmq-all-trans,代码行数:45,代码来源:QueryMsgByOffsetSubCommand.java

示例11: run

import com.alibaba.rocketmq.client.consumer.PullResult; //导入方法依赖的package包/类
@Override
public void run() {

	while (this.isOK.get()) {
		System.out.println("Consume from the queue: " + partition);

		try {
			// 获取上一次的消费进度
			long nextOffset = getMessageQueueOffset(consumer, partition, true);

			for (;;) {
				// 根据消费进度,获取下一批消息
				PullResult pullResult = consumer.pullBlockIfNotFound(partition, null, nextOffset, 32);

				switch (pullResult.getPullStatus()) {
				case FOUND:
					// 处理消息列表
					int index = 0;
					
					for (MessageExt msg : pullResult.getMsgFoundList()) {
						index++;
						boolean isMsgFailed = false;
						System.out.println(msg);
						
						// mock
						if (index % 2 ==0) { 
							isMsgFailed = true; 
						}
						// the message failed, need to send back to wait for retry.
						if (isMsgFailed) {
							this.consumer.sendMessageBack(msg, 2);
						}
					}
					// 处理完成,让broker保存消费进度
					putMessageQueueOffset(consumer, partition, pullResult.getNextBeginOffset());
					nextOffset = pullResult.getNextBeginOffset();

					break;
				case NO_MATCHED_MSG:
					break;
				case NO_NEW_MSG:
					break;
				case OFFSET_ILLEGAL:
					break;
				default:
					break;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	// current task is ready to stop
	this.stopLatch.countDown();

	System.out.println("notified to stop");
}
 
开发者ID:brucechan0921,项目名称:RocketMQ-3.0.8,代码行数:59,代码来源:PullMsgFromMqTask.java


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