com.alibaba.rocketmq.client.consumer.PullResult Java Examples
The following examples show how to use
com.alibaba.rocketmq.client.consumer.PullResult.
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: MQClientAPIImpl.java From rocketmq with Apache License 2.0 | 6 votes |
public PullResult pullMessage(// final String addr, // final PullMessageRequestHeader requestHeader, // final long timeoutMillis, // final CommunicationMode communicationMode, // final PullCallback pullCallback// ) throws RemotingException, MQBrokerException, InterruptedException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.PULL_MESSAGE, requestHeader); switch (communicationMode) { case ONEWAY: assert false; return null; case ASYNC: this.pullMessageAsync(addr, request, timeoutMillis, pullCallback); return null; case SYNC: return this.pullMessageSync(addr, request, timeoutMillis); default: assert false; break; } return null; }
Example #2
Source File: PullConsumerTest.java From rocketmq with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws MQClientException { DefaultMQPullConsumer consumer = new DefaultMQPullConsumer("please_rename_unique_group_name_5"); consumer.start(); try { MessageQueue mq = new MessageQueue(); mq.setQueueId(0); mq.setTopic("TopicTest3"); mq.setBrokerName("vivedeMacBook-Pro.local"); long offset = 26; long beginTime = System.currentTimeMillis(); PullResult pullResult = consumer.pullBlockIfNotFound(mq, null, offset, 32); System.out.println(System.currentTimeMillis() - beginTime); System.out.println(pullResult); } catch (Exception e) { e.printStackTrace(); } consumer.shutdown(); }
Example #3
Source File: PullConsumerTest.java From RocketMQ-Master-analyze with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws MQClientException { DefaultMQPullConsumer consumer = new DefaultMQPullConsumer("please_rename_unique_group_name_5"); consumer.start(); try { MessageQueue mq = new MessageQueue(); mq.setQueueId(0); mq.setTopic("TopicTest3"); mq.setBrokerName("vivedeMacBook-Pro.local"); long offset = 26; long beginTime = System.currentTimeMillis(); PullResult pullResult = consumer.pullBlockIfNotFound(mq, null, offset, 32); System.out.println(System.currentTimeMillis() - beginTime); System.out.println(pullResult); } catch (Exception e) { e.printStackTrace(); } consumer.shutdown(); }
Example #4
Source File: MQClientAPIImpl.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 6 votes |
public PullResult pullMessage(// final String addr,// final PullMessageRequestHeader requestHeader,// final long timeoutMillis,// final CommunicationMode communicationMode,// final PullCallback pullCallback// ) throws RemotingException, MQBrokerException, InterruptedException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.PULL_MESSAGE, requestHeader); switch (communicationMode) { case ONEWAY: assert false; return null; case ASYNC: this.pullMessageAsync(addr, request, timeoutMillis, pullCallback); return null; case SYNC: return this.pullMessageSync(addr, request, timeoutMillis); default: assert false; break; } return null; }
Example #5
Source File: MQClientAPIImpl.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 6 votes |
private PullResult processPullResponse(final RemotingCommand response) throws MQBrokerException, RemotingCommandException { PullStatus pullStatus = PullStatus.NO_NEW_MSG; switch (response.getCode()) { case ResponseCode.SUCCESS: pullStatus = PullStatus.FOUND; break; case ResponseCode.PULL_NOT_FOUND: pullStatus = PullStatus.NO_NEW_MSG; break; case ResponseCode.PULL_RETRY_IMMEDIATELY: pullStatus = PullStatus.NO_MATCHED_MSG; break; case ResponseCode.PULL_OFFSET_MOVED: pullStatus = PullStatus.OFFSET_ILLEGAL; break; default: throw new MQBrokerException(response.getCode(), response.getRemark()); } PullMessageResponseHeader responseHeader = (PullMessageResponseHeader) response.decodeCommandCustomHeader(PullMessageResponseHeader.class); return new PullResultExt(pullStatus, responseHeader.getNextBeginOffset(), responseHeader.getMinOffset(), responseHeader.getMaxOffset(), null, responseHeader.getSuggestWhichBrokerId(), response.getBody()); }
Example #6
Source File: MQClientAPIImpl.java From rocketmq with Apache License 2.0 | 6 votes |
private PullResult processPullResponse(final RemotingCommand response) throws MQBrokerException, RemotingCommandException { PullStatus pullStatus = PullStatus.NO_NEW_MSG; switch (response.getCode()) { case ResponseCode.SUCCESS: pullStatus = PullStatus.FOUND; break; case ResponseCode.PULL_NOT_FOUND: pullStatus = PullStatus.NO_NEW_MSG; break; case ResponseCode.PULL_RETRY_IMMEDIATELY: pullStatus = PullStatus.NO_MATCHED_MSG; break; case ResponseCode.PULL_OFFSET_MOVED: pullStatus = PullStatus.OFFSET_ILLEGAL; break; default: throw new MQBrokerException(response.getCode(), response.getRemark()); } PullMessageResponseHeader responseHeader = (PullMessageResponseHeader) response.decodeCommandCustomHeader(PullMessageResponseHeader.class); return new PullResultExt(pullStatus, responseHeader.getNextBeginOffset(), responseHeader.getMinOffset(), responseHeader.getMaxOffset(), null, responseHeader.getSuggestWhichBrokerId(), response.getBody()); }
Example #7
Source File: PullConsumerTest.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 6 votes |
public static void main(String[] args) throws MQClientException { DefaultMQPullConsumer consumer = new DefaultMQPullConsumer("please_rename_unique_group_name_5"); consumer.start(); try { MessageQueue mq = new MessageQueue(); mq.setQueueId(0); mq.setTopic("TopicTest3"); mq.setBrokerName("vivedeMacBook-Pro.local"); long offset = 26; long beginTime = System.currentTimeMillis(); PullResult pullResult = consumer.pullBlockIfNotFound(mq, null, offset, 32); System.out.println(System.currentTimeMillis() - beginTime); System.out.println(pullResult); } catch (Exception e) { e.printStackTrace(); } consumer.shutdown(); }
Example #8
Source File: PullScheduleService.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 { final MQPullConsumerScheduleService scheduleService = new MQPullConsumerScheduleService("GroupName1"); scheduleService.setMessageModel(MessageModel.CLUSTERING); scheduleService.registerPullTaskCallback("TopicTest1", new PullTaskCallback() { @Override public void doPullTask(MessageQueue mq, PullTaskContext context) { MQPullConsumer consumer = context.getPullConsumer(); try { long offset = consumer.fetchConsumeOffset(mq, false); if (offset < 0) offset = 0; PullResult pullResult = consumer.pull(mq, "*", offset, 32); System.out.println(offset + "\t" + mq + "\t" + pullResult); switch (pullResult.getPullStatus()) { case FOUND: break; case NO_MATCHED_MSG: break; case NO_NEW_MSG: case OFFSET_ILLEGAL: break; default: break; } consumer.updateConsumeOffset(mq, pullResult.getNextBeginOffset()); context.setPullNextDelayTimeMillis(100); } catch (Exception e) { e.printStackTrace(); } } }); scheduleService.start(); }
Example #9
Source File: MQClientAPIImpl.java From rocketmq with Apache License 2.0 | 5 votes |
private PullResult pullMessageSync(// final String addr, // 1 final RemotingCommand request, // 2 final long timeoutMillis// 3 ) throws RemotingException, InterruptedException, MQBrokerException { RemotingCommand response = this.remotingClient.invokeSync(addr, request, timeoutMillis); assert response != null; return this.processPullResponse(response); }
Example #10
Source File: MQClientAPIImpl.java From RocketMQ-Master-analyze with Apache License 2.0 | 5 votes |
/** * 客户端拉取消息通用方法 * * @param addr * @param requestHeader * @param timeoutMillis * @param communicationMode * @param pullCallback * @return * @throws RemotingException * @throws MQBrokerException * @throws InterruptedException */ public PullResult pullMessage(final String addr, final PullMessageRequestHeader requestHeader, final long timeoutMillis, final CommunicationMode communicationMode, final PullCallback pullCallback) throws RemotingException, MQBrokerException, InterruptedException { if (!UtilAll.isBlank(projectGroupPrefix)) { requestHeader.setConsumerGroup( VirtualEnvUtil.buildWithProjectGroup(requestHeader.getConsumerGroup(), projectGroupPrefix)); requestHeader .setTopic(VirtualEnvUtil.buildWithProjectGroup(requestHeader.getTopic(), projectGroupPrefix)); } RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.PULL_MESSAGE, requestHeader); switch (communicationMode) { case ONEWAY: assert false; return null; case ASYNC: this.pullMessageAsync(addr, request, timeoutMillis, pullCallback); return null; case SYNC: return this.pullMessageSync(addr, request, timeoutMillis); default: assert false; break; } return null; }
Example #11
Source File: MQClientAPIImpl.java From RocketMQ-Master-analyze with Apache License 2.0 | 5 votes |
/** * 处理拉取消息的响应 * * @param response * @return * @throws MQBrokerException * @throws RemotingCommandException */ private PullResult processPullResponse(final RemotingCommand response) throws MQBrokerException, RemotingCommandException { PullStatus pullStatus = PullStatus.NO_NEW_MSG; switch (response.getCode()) { case ResponseCode.SUCCESS: pullStatus = PullStatus.FOUND; break; case ResponseCode.PULL_NOT_FOUND: pullStatus = PullStatus.NO_NEW_MSG; break; case ResponseCode.PULL_RETRY_IMMEDIATELY: pullStatus = PullStatus.NO_MATCHED_MSG; break; case ResponseCode.PULL_OFFSET_MOVED: pullStatus = PullStatus.OFFSET_ILLEGAL; break; default: throw new MQBrokerException(response.getCode(), response.getRemark()); } PullMessageResponseHeader responseHeader = (PullMessageResponseHeader) response .decodeCommandCustomHeader(PullMessageResponseHeader.class); return new PullResultExt(pullStatus, responseHeader.getNextBeginOffset(), responseHeader.getMinOffset(), responseHeader.getMaxOffset(), null, responseHeader.getSuggestWhichBrokerId(), response.getBody()); }
Example #12
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 #13
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 #14
Source File: MQClientAPIImpl.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 5 votes |
private PullResult pullMessageSync(// final String addr,// 1 final RemotingCommand request,// 2 final long timeoutMillis// 3 ) throws RemotingException, InterruptedException, MQBrokerException { RemotingCommand response = this.remotingClient.invokeSync(addr, request, timeoutMillis); assert response != null; return this.processPullResponse(response); }
Example #15
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 #16
Source File: DefaultMQPullConsumerImpl.java From RocketMQ-Master-analyze with Apache License 2.0 | 4 votes |
public PullResult pull(MessageQueue mq, String subExpression, long offset, int maxNums) throws MQClientException, RemotingException, MQBrokerException, InterruptedException { return pull(mq, subExpression, offset, maxNums, this.defaultMQPullConsumer.getConsumerPullTimeoutMillis()); }
Example #17
Source File: DefaultMQPullConsumerImpl.java From RocketMQ-Master-analyze with Apache License 2.0 | 4 votes |
public PullResult pull(MessageQueue mq, String subExpression, long offset, int maxNums, long timeout) throws MQClientException, RemotingException, MQBrokerException, InterruptedException { return this.pullSyncImpl(mq, subExpression, offset, maxNums, false, timeout); }
Example #18
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; }
Example #19
Source File: DefaultMQPullConsumerImpl.java From RocketMQ-Master-analyze with Apache License 2.0 | 4 votes |
private PullResult pullSyncImpl(MessageQueue mq, String subExpression, long offset, int maxNums, boolean block, long timeout) throws MQClientException, RemotingException, MQBrokerException, InterruptedException { this.makeSureStateOK(); if (null == mq) { throw new MQClientException("mq is null", null); } if (offset < 0) { throw new MQClientException("offset < 0", null); } if (maxNums <= 0) { throw new MQClientException("maxNums <= 0", null); } this.subscriptionAutomatically(mq.getTopic()); int sysFlag = PullSysFlag.buildSysFlag(false, block, true, false); SubscriptionData subscriptionData; try { subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPullConsumer.getConsumerGroup(), // mq.getTopic(), subExpression); } catch (Exception e) { throw new MQClientException("parse subscription error", e); } long timeoutMillis = block ? this.defaultMQPullConsumer.getConsumerTimeoutMillisWhenSuspend() : timeout; PullResult pullResult = this.pullAPIWrapper.pullKernelImpl(// mq, // 1 subscriptionData.getSubString(), // 2 0L, // 3 offset, // 4 maxNums, // 5 sysFlag, // 6 0, // 7 this.defaultMQPullConsumer.getBrokerSuspendMaxTimeMillis(), // 8 timeoutMillis, // 9 CommunicationMode.SYNC, // 10 null// 11 ); return this.pullAPIWrapper.processPullResult(mq, pullResult, subscriptionData); }
Example #20
Source File: DefaultMQPullConsumerImpl.java From RocketMQ-Master-analyze with Apache License 2.0 | 4 votes |
public PullResult pullBlockIfNotFound(MessageQueue mq, String subExpression, long offset, int maxNums) throws MQClientException, RemotingException, MQBrokerException, InterruptedException { return this.pullSyncImpl(mq, subExpression, offset, maxNums, true, this.getDefaultMQPullConsumer().getConsumerPullTimeoutMillis()); }
Example #21
Source File: PullAPIWrapper.java From RocketMQ-Master-analyze with Apache License 2.0 | 4 votes |
public PullResult pullKernelImpl(// final MessageQueue mq, // 1 final String subExpression, // 2 final long subVersion, // 3 final long offset, // 4 final int maxNums, // 5 final int sysFlag, // 6 final long commitOffset, // 7 final long brokerSuspendMaxTimeMillis, // 8 final long timeoutMillis, // 9 final CommunicationMode communicationMode, // 10 final PullCallback pullCallback// 11 ) throws MQClientException, RemotingException, MQBrokerException, InterruptedException { FindBrokerResult findBrokerResult = this.mQClientFactory .findBrokerAddressInSubscribe(mq.getBrokerName(), this.recalculatePullFromWhichNode(mq), false); if (null == findBrokerResult) { this.mQClientFactory.updateTopicRouteInfoFromNameServer(mq.getTopic()); findBrokerResult = this.mQClientFactory.findBrokerAddressInSubscribe(mq.getBrokerName(), this.recalculatePullFromWhichNode(mq), false); } if (findBrokerResult != null) { int sysFlagInner = sysFlag; if (findBrokerResult.isSlave()) { sysFlagInner = PullSysFlag.clearCommitOffsetFlag(sysFlagInner); } PullMessageRequestHeader requestHeader = new PullMessageRequestHeader(); requestHeader.setConsumerGroup(this.consumerGroup); requestHeader.setTopic(mq.getTopic()); requestHeader.setQueueId(mq.getQueueId()); requestHeader.setQueueOffset(offset); requestHeader.setMaxMsgNums(maxNums); requestHeader.setSysFlag(sysFlagInner); requestHeader.setCommitOffset(commitOffset); requestHeader.setSuspendTimeoutMillis(brokerSuspendMaxTimeMillis); requestHeader.setSubscription(subExpression); requestHeader.setSubVersion(subVersion); String brokerAddr = findBrokerResult.getBrokerAddr(); if (PullSysFlag.hasClassFilterFlag(sysFlagInner)) { brokerAddr = computPullFromWhichFilterServer(mq.getTopic(), brokerAddr); } PullResult pullResult = this.mQClientFactory.getMQClientAPIImpl().pullMessage(// brokerAddr, // requestHeader, // timeoutMillis, // communicationMode, // pullCallback); return pullResult; } throw new MQClientException("The broker[" + mq.getBrokerName() + "] not exist", null); }
Example #22
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 #23
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 #24
Source File: DefaultMQPullConsumerImpl.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 4 votes |
public PullResult pull(MessageQueue mq, String subExpression, long offset, int maxNums) throws MQClientException, RemotingException, MQBrokerException, InterruptedException { return pull(mq, subExpression, offset, maxNums, this.defaultMQPullConsumer.getConsumerPullTimeoutMillis()); }
Example #25
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 #26
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 #27
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 #28
Source File: PullAPIWrapper.java From rocketmq with Apache License 2.0 | 4 votes |
public PullResult pullKernelImpl(// final MessageQueue mq,// 1 final String subExpression,// 2 final long subVersion,// 3 final long offset,// 4 final int maxNums,// 5 final int sysFlag,// 6 final long commitOffset,// 7 final long brokerSuspendMaxTimeMillis,// 8 final long timeoutMillis,// 9 final CommunicationMode communicationMode,// 10 final PullCallback pullCallback// 11 ) throws MQClientException, RemotingException, MQBrokerException, InterruptedException { FindBrokerResult findBrokerResult = this.mQClientFactory.findBrokerAddressInSubscribe(mq.getBrokerName(), this.recalculatePullFromWhichNode(mq), false); if (null == findBrokerResult) { this.mQClientFactory.updateTopicRouteInfoFromNameServer(mq.getTopic()); findBrokerResult = this.mQClientFactory.findBrokerAddressInSubscribe(mq.getBrokerName(), this.recalculatePullFromWhichNode(mq), false); } if (findBrokerResult != null) { int sysFlagInner = sysFlag; if (findBrokerResult.isSlave()) { sysFlagInner = PullSysFlag.clearCommitOffsetFlag(sysFlagInner); } PullMessageRequestHeader requestHeader = new PullMessageRequestHeader(); requestHeader.setConsumerGroup(this.consumerGroup); requestHeader.setTopic(mq.getTopic()); requestHeader.setQueueId(mq.getQueueId()); requestHeader.setQueueOffset(offset); requestHeader.setMaxMsgNums(maxNums); requestHeader.setSysFlag(sysFlagInner); requestHeader.setCommitOffset(commitOffset); requestHeader.setSuspendTimeoutMillis(brokerSuspendMaxTimeMillis); requestHeader.setSubscription(subExpression); requestHeader.setSubVersion(subVersion); String brokerAddr = findBrokerResult.getBrokerAddr(); if (PullSysFlag.hasClassFilterFlag(sysFlagInner)) { brokerAddr = computPullFromWhichFilterServer(mq.getTopic(), brokerAddr); } PullResult pullResult = this.mQClientFactory.getMQClientAPIImpl().pullMessage(// brokerAddr,// requestHeader,// timeoutMillis,// communicationMode,// pullCallback); return pullResult; } throw new MQClientException("The broker[" + mq.getBrokerName() + "] not exist", null); }
Example #29
Source File: DefaultMQPullConsumerImpl.java From rocketmq with Apache License 2.0 | 4 votes |
public PullResult pullBlockIfNotFound(MessageQueue mq, String subExpression, long offset, int maxNums) throws MQClientException, RemotingException, MQBrokerException, InterruptedException { return this.pullSyncImpl(mq, subExpression, offset, maxNums, true, this.getDefaultMQPullConsumer().getConsumerPullTimeoutMillis()); }
Example #30
Source File: DefaultMQPullConsumerImpl.java From rocketmq with Apache License 2.0 | 4 votes |
public PullResult pull(MessageQueue mq, String subExpression, long offset, int maxNums, long timeout) throws MQClientException, RemotingException, MQBrokerException, InterruptedException { return this.pullSyncImpl(mq, subExpression, offset, maxNums, false, timeout); }