Java Code Examples for com.alibaba.rocketmq.client.consumer.PullResult#getPullStatus()
The following examples show how to use
com.alibaba.rocketmq.client.consumer.PullResult#getPullStatus() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PullConsumer.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 5 votes |
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(); }
Example 2
Source File: PullConsumer.java From rocketmq with Apache License 2.0 | 5 votes |
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(); }
Example 3
Source File: PullConsumer.java From RocketMQ-Master-analyze with Apache License 2.0 | 5 votes |
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(); }
Example 4
Source File: QueryMsgByOffsetSubCommand.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 4 votes |
@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(); } }
Example 5
Source File: MonitorService.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 4 votes |
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); }
Example 6
Source File: MessageService.java From rocketmq with Apache License 2.0 | 4 votes |
@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; }
Example 7
Source File: QueryMsgByOffsetSubCommand.java From rocketmq with Apache License 2.0 | 4 votes |
@Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); DefaultMQPullConsumer defaultMQPullConsumer = new DefaultMQPullConsumer(MixAll.TOOLS_CONSUMER_GROUP,rpcHook); 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(); } }
Example 8
Source File: MonitorService.java From rocketmq with Apache License 2.0 | 4 votes |
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); }
Example 9
Source File: QueryMsgByOffsetSubCommand.java From RocketMQ-Master-analyze with Apache License 2.0 | 4 votes |
@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(); } }
Example 10
Source File: MonitorService.java From RocketMQ-Master-analyze with Apache License 2.0 | 4 votes |
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); }
Example 11
Source File: MetaSimpleClient.java From jstorm with Apache License 2.0 | 4 votes |
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; }