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


Java MessageExt.getReconsumeTimes方法代码示例

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


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

示例1: consumeMessage

import com.alibaba.rocketmq.common.message.MessageExt; //导入方法依赖的package包/类
@Override
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs,
		ConsumeConcurrentlyContext context)
{
	LOGGER.info(" 当前处理的消息是 " + MessageHelp.GetMessagesToString(msgs));

	MessageExt msg = msgs.get(0);
	String strBody = null;
	try
	{
		// 直接在第一次 字节转换字符串的时候就指定为 UTF-8 编码
		strBody = new String(msg.getBody(), Encoding);
	}
	catch (UnsupportedEncodingException e1)
	{
		LOGGER.error("获取数据为UTF-8格式出错    ", e1);
		strBody = new String(msg.getBody());
	}

	LOGGER.info("当前处理的消息 实体是 " + strBody);

	// 消息处理次数的处理
	if (msg.getReconsumeTimes() > count)
	{
		LOGGER.info("容错次数超出  msg=" + msg);
		return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
	}
	return consumer.consumeMessage(strBody, msg, context);
}
 
开发者ID:atliwen,项目名称:rocketMqCurrency,代码行数:30,代码来源:DefaultMessageListener.java

示例2: testget

import com.alibaba.rocketmq.common.message.MessageExt; //导入方法依赖的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


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