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


Java PullResult.getMsgFoundList方法代码示例

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


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

示例1: testRecodeMessage

import com.alibaba.rocketmq.client.consumer.PullResult; //导入方法依赖的package包/类
/**
 * 实时更新offerset
 */
@Test
public void testRecodeMessage() {
    long offset = 0;
    try {
        PullResult pullResult = consumer.pull(mq, null, offset, 9);
        List<MessageExt> msgFoundList = pullResult.getMsgFoundList();
        for (MessageExt ms : msgFoundList) {
            long queueOffset = ms.getQueueOffset();
            saveOfferSet(queueOffset, offsetStore, mq);
        }
        //更新offerset
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:bigdatafly,项目名称:flume-rocketmq-sink,代码行数:19,代码来源:PullConsumerTest.java

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

示例3: testget

import com.alibaba.rocketmq.client.consumer.PullResult; //导入方法依赖的package包/类
@Test
    public void testget() throws MQClientException {
        try {

            long l = consumer.fetchConsumeOffset(mq, false);
            System.out.println("-----------" + l);

            PullResult pr = null;


            long beginTime = System.currentTimeMillis();

            consumer.updateConsumeOffset(mq, 9);
            l = consumer.fetchConsumeOffset(mq, false);
            System.out.println("-----------" + l);
            long offset = 0;
            PullResult pullResult = consumer.pull(mq, null, offset, 9);

//            QueryResult topic2 = consumer.queryMessage("Topic2", 25 + "", 1, 2, 3);
            MessageExt ac1B654300002A9F0000000000022E35 = consumer.viewMessage("AC1B654300002A9F0000000000022E35");
            System.out.println("this is the " + new String(ac1B654300002A9F0000000000022E35.getBody())); //Hello RocketMQ 29
            HashMap<String, MessageExt> success = new HashMap<String, MessageExt>();
            System.out.println(System.currentTimeMillis() - beginTime);
            System.out.println(pullResult);
            List<MessageExt> msgFoundList = pullResult.getMsgFoundList();
            List<MessageExt> msgFail = new ArrayList<MessageExt>();
            Random random = new Random();
            for (MessageExt ms : msgFoundList) {
                int reconsumeTimes = ms.getReconsumeTimes();
                System.out.println("this is " + reconsumeTimes);
                ms.setReconsumeTimes(reconsumeTimes + 1);
                int i = random.nextInt();
                if ((i & 2) == 0) {
                    System.out.println("事物成功");
                    success.put(ms.getMsgId(), ms);
                } else {
                    System.out.println("事物失败");
                    msgFail.add(ms);
                }
            }
            System.out.println("第一次执行失败" + msgFail.size() + "个");

            boolean check = check(msgFoundList, success);
            if (!check) {
                while (msgFail.size() != 0) {
                    for (int i = 0; i < msgFail.size(); i++) {
                        int rd = random.nextInt() % 2;
                        if ((rd & 2) == 0) {
                            System.out.println("执行成功");
                            success.put(msgFail.get(i).getMsgId(), msgFail.get(i));
                            msgFail.remove(i);
                            System.out.println("还剩下" + msgFail.size() + "个事件");
                        } else {
                            System.out.println("执行失败");
                            System.out.println("还剩下" + msgFail.size() + "个事件");
                        }
                    }
                    System.out.println("等待1000毫秒后重试");
                    Thread.sleep(1000);
                }
            }
            System.out.println("一共执行" + msgFoundList.size() + "个事件");
            System.out.println("执行成功" + success.size() + "个");
            //QueueOffsetCache.putMessageQueueOffset(mq, pullResult.getNextBeginOffset());
            System.out.println(consumer.maxOffset(mq));
        } catch (Exception e) {
            e.printStackTrace();
        }

        consumer.shutdown();
    }
 
开发者ID:bigdatafly,项目名称:flume-rocketmq-sink,代码行数:72,代码来源:PullConsumerTest.java

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

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