com.alibaba.rocketmq.common.sysflag.PullSysFlag Java Examples
The following examples show how to use
com.alibaba.rocketmq.common.sysflag.PullSysFlag.
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: DefaultMQPullConsumerImpl.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.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 #2
Source File: PullAPIWrapper.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.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) { //PullAPIWrapper.pullKernelImpl中调用updateTopicRouteInfoFromNameServer进行TopicRoute信息更新,最终保存在MQClientInstance.topicRouteTable this.mQClientFactory.updateTopicRouteInfoFromNameServer(mq.getTopic()); findBrokerResult = this.mQClientFactory.findBrokerAddressInSubscribe(mq.getBrokerName(), this.recalculatePullFromWhichNode(mq), false); } if (findBrokerResult != null) { int sysFlagInner = sysFlag; if (findBrokerResult.isSlave()) { //拉取broker选择了slave, 清理掉提交消费位点的系统标识位。 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); } //开始从broker对应的brokerAddr拉取消息 PullResult pullResult = this.mQClientFactory.getMQClientAPIImpl().pullMessage(// brokerAddr,// requestHeader,// timeoutMillis,// communicationMode,//同步从broker拉取消息还是异步拉取消息 pullCallback); return pullResult; } throw new MQClientException("The broker[" + mq.getBrokerName() + "] not exist", null); }
Example #3
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 #4
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 #5
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); }