本文整理汇总了Java中com.alibaba.rocketmq.common.message.MessageExt.getQueueOffset方法的典型用法代码示例。如果您正苦于以下问题:Java MessageExt.getQueueOffset方法的具体用法?Java MessageExt.getQueueOffset怎么用?Java MessageExt.getQueueOffset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.rocketmq.common.message.MessageExt
的用法示例。
在下文中一共展示了MessageExt.getQueueOffset方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: consumed
import com.alibaba.rocketmq.common.message.MessageExt; //导入方法依赖的package包/类
public boolean consumed(final MessageExt msg, final String group) throws RemotingException, MQClientException, InterruptedException,
MQBrokerException {
ConsumeStats cstats = this.examineConsumeStats(group);
ClusterInfo ci = this.examineBrokerClusterInfo();
Iterator<Entry<MessageQueue, OffsetWrapper>> it = cstats.getOffsetTable().entrySet().iterator();
while (it.hasNext()) {
Entry<MessageQueue, OffsetWrapper> next = it.next();
MessageQueue mq = next.getKey();
if (mq.getTopic().equals(msg.getTopic()) && mq.getQueueId() == msg.getQueueId()) {
BrokerData brokerData = ci.getBrokerAddrTable().get(mq.getBrokerName());
if (brokerData != null) {
String addr = brokerData.getBrokerAddrs().get(MixAll.MASTER_ID);
if (addr.equals(RemotingUtil.socketAddress2String(msg.getStoreHost()))) {
if (next.getValue().getConsumerOffset() > msg.getQueueOffset()) {
return true;
}
}
}
}
}
return false;
}
示例2: testRecodeMessage
import com.alibaba.rocketmq.common.message.MessageExt; //导入方法依赖的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();
}
}
示例3: consumed
import com.alibaba.rocketmq.common.message.MessageExt; //导入方法依赖的package包/类
public boolean consumed(final MessageExt msg, final String group) throws RemotingException, MQClientException, InterruptedException,
MQBrokerException {
ConsumeStats cstats = this.examineConsumeStats(group);
ClusterInfo ci = this.examineBrokerClusterInfo();
Iterator<Entry<MessageQueue, OffsetWrapper>> it = cstats.getOffsetTable().entrySet().iterator();
while (it.hasNext()) {
Entry<MessageQueue, OffsetWrapper> next = it.next();
MessageQueue mq = next.getKey();
if (mq.getTopic().equals(msg.getTopic()) && mq.getQueueId() == msg.getQueueId()) {
BrokerData brokerData = ci.getBrokerAddrTable().get(mq.getBrokerName());
if (brokerData != null) {
String addr = brokerData.getBrokerAddrs().get(MixAll.MASTER_ID);
if (addr.equals(RemotingUtil.socketAddress2String(msg.getStoreHost()))) {
/* 检查msg是否已经被消费,根据offset进行比较 */
if (next.getValue().getConsumerOffset() > msg.getQueueOffset()) {
return true;
}
}
}
}
}
/* 还没有被消费 */
return false;
}
示例4: putMessage
import com.alibaba.rocketmq.common.message.MessageExt; //导入方法依赖的package包/类
public boolean putMessage(final List<MessageExt> msgs) {
boolean dispatchToConsume = false;
try {
this.lockTreeMap.writeLock().lockInterruptibly();
try {
int validMsgCnt = 0;
for (MessageExt msg : msgs) {
//把拉取到的消息存入msgTreeMap中
MessageExt old = msgTreeMap.put(msg.getQueueOffset(), msg);
if (null == old) {
validMsgCnt++;
/* 更新队列queueoffset */
this.queueOffsetMax = msg.getQueueOffset();
}
}
//msg数增加validMsgCnt
msgCount.addAndGet(validMsgCnt);
if (!msgTreeMap.isEmpty() && !this.consuming) {
dispatchToConsume = true;
this.consuming = true;
}
if (!msgs.isEmpty()) {
MessageExt messageExt = msgs.get(msgs.size() - 1); //获取最后一条消息
String property = messageExt.getProperty(MessageConst.PROPERTY_MAX_OFFSET);
if (property != null) {
//在消息属性PROPERTY_MAX_OFFSET中记录了队列的最大位点, 和当前拉取到的最后一条消息
//的位点做差值,就是broker这个队列还堆积了多少消息未消费。。 messageExt.getQueueOffset()表示从队列中取到的最后一条消息
//该getQueueOffset对应的就是从队列中拉取到的最后一条消息的offset,也就是该消费分组消费到队列中的那条offset最大的消息
long accTotal = Long.parseLong(property) - messageExt.getQueueOffset();
if (accTotal > 0) {
this.msgAccCnt = accTotal;
}
}
}
}
finally {
this.lockTreeMap.writeLock().unlock();
}
}
catch (InterruptedException e) {
log.error("putMessage exception", e);
}
return dispatchToConsume;
}
示例5: putMessage
import com.alibaba.rocketmq.common.message.MessageExt; //导入方法依赖的package包/类
/**
* 放入消息到ProcessQueue
*
* @param msgs
* @return
*/
public boolean putMessage(final List<MessageExt> msgs) {
boolean dispatchToConsume = false;
try {
this.lockTreeMap.writeLock().lockInterruptibly();
try {
/**
* 把消息放入treemap,根据offset值去除重复消息,统计有效消息数量,更新Offset
*
* 消息以Offset为Key放入了treemap,则默认会按照offset的升序排序
*
*/
int validMsgCnt = 0;
for (MessageExt msg : msgs) {
MessageExt old = msgTreeMap.put(msg.getQueueOffset(), msg);
if (null == old) {
validMsgCnt++;
this.queueOffsetMax = msg.getQueueOffset();
}
}
msgCount.addAndGet(validMsgCnt);
if (!msgTreeMap.isEmpty() && !this.consuming) {
dispatchToConsume = true;
this.consuming = true;
}
if (!msgs.isEmpty()) {
//获取最后一条消息的MaxOffSet
MessageExt messageExt = msgs.get(msgs.size() - 1);
String property = messageExt.getProperty(MessageConst.PROPERTY_MAX_OFFSET);
if (property != null) {
/**
* commitlog offset
* 减去
* 消息对应MessageQueue的Offset
*
*/
long accTotal = Long.parseLong(property) - messageExt.getQueueOffset();
if (accTotal > 0) {
this.msgAccCnt = accTotal;
}
}
}
} finally {
this.lockTreeMap.writeLock().unlock();
}
} catch (InterruptedException e) {
log.error("putMessage exception", e);
}
return dispatchToConsume;
}