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


Java PullResult.getNextBeginOffset方法代码示例

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


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

示例1: 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

示例2: 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.getNextBeginOffset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。