Java Code Examples for com.alibaba.rocketmq.common.message.MessageExt#getProperty()

The following examples show how to use com.alibaba.rocketmq.common.message.MessageExt#getProperty() . 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: ClientRemotingProcessor.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public RemotingCommand checkTransactionState(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
    final CheckTransactionStateRequestHeader requestHeader =
            (CheckTransactionStateRequestHeader) request.decodeCommandCustomHeader(CheckTransactionStateRequestHeader.class);
    final ByteBuffer byteBuffer = ByteBuffer.wrap(request.getBody());
    final MessageExt messageExt = MessageDecoder.decode(byteBuffer);
    if (messageExt != null) {
        final String group = messageExt.getProperty(MessageConst.PROPERTY_PRODUCER_GROUP);
        if (group != null) {
            MQProducerInner producer = this.mqClientFactory.selectProducer(group);
            if (producer != null) {
                final String addr = RemotingHelper.parseChannelRemoteAddr(ctx.channel());
                producer.checkTransactionState(addr, messageExt, requestHeader);
            } else {
                log.debug("checkTransactionState, pick producer by group[{}] failed", group);
            }
        } else {
            log.warn("checkTransactionState, pick producer group failed");
        }
    } else {
        log.warn("checkTransactionState, decode message failed");
    }

    return null;
}
 
Example 2
Source File: ConsumeMessageConcurrentlyService.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
public void resetRetryTopic(final List<MessageExt> msgs) {
    final String groupTopic = MixAll.getRetryTopic(consumerGroup);
    for (MessageExt msg : msgs) {
        String retryTopic = msg.getProperty(MessageConst.PROPERTY_RETRY_TOPIC);
        if (retryTopic != null && groupTopic.equals(msg.getTopic())) {
            msg.setTopic(retryTopic);
        }
    }
}
 
Example 3
Source File: ClientRemotingProcessor.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
public RemotingCommand checkTransactionState(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
    final CheckTransactionStateRequestHeader requestHeader =
            (CheckTransactionStateRequestHeader) request.decodeCommandCustomHeader(CheckTransactionStateRequestHeader.class);
    final ByteBuffer byteBuffer = ByteBuffer.wrap(request.getBody());
    final MessageExt messageExt = MessageDecoder.decode(byteBuffer);
    if (messageExt != null) {
        final String group = messageExt.getProperty(MessageConst.PROPERTY_PRODUCER_GROUP);
        if (group != null) {
            MQProducerInner producer = this.mqClientFactory.selectProducer(group);
            if (producer != null) {
                final String addr = RemotingHelper.parseChannelRemoteAddr(ctx.channel());
                producer.checkTransactionState(addr, messageExt, requestHeader);
            }
            else {
                log.debug("checkTransactionState, pick producer by group[{}] failed", group);
            }
        }
        else {
            log.warn("checkTransactionState, pick producer group failed");
        }
    }
    else {
        log.warn("checkTransactionState, decode message failed");
    }

    return null;
}
 
Example 4
Source File: MessageFilterImpl.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean match(MessageExt msg) {
    String property = msg.getProperty("SequenceId");
    if (property != null) {
        int id = Integer.parseInt(property);
        if (((id % 10) == 0) && //
                (id > 100)) {
            return true;
        }
    }

    return false;
}
 
Example 5
Source File: MessageFilterImpl.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean match(MessageExt msg) {
    String property = msg.getProperty("SequenceId");
    if (property != null) {
        int id = Integer.parseInt(property);
        if (((id % 10) == 0) && //
                (id > 100)) {
            return true;
        }
    }

    return false;
}
 
Example 6
Source File: ProcessQueue.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public boolean putMessage(final List<MessageExt> msgs) {
    boolean dispatchToConsume = false;
    try {
        this.lockTreeMap.writeLock().lockInterruptibly();
        try {
            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()) {
                MessageExt messageExt = msgs.get(msgs.size() - 1);
                String property = messageExt.getProperty(MessageConst.PROPERTY_MAX_OFFSET);
                if (property != null) {
                    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;
}
 
Example 7
Source File: ConsumeMessageConcurrentlyService.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public void resetRetryTopic(final List<MessageExt> msgs) {
    final String groupTopic = MixAll.getRetryTopic(consumerGroup);
    for (MessageExt msg : msgs) {
        String retryTopic = msg.getProperty(MessageConst.PROPERTY_RETRY_TOPIC);
        if (retryTopic != null && groupTopic.equals(msg.getTopic())) {
            msg.setTopic(retryTopic);
        }
    }
}
 
Example 8
Source File: RocketMQPushConsumerStarter.java    From onetwo with Apache License 2.0 5 votes vote down vote up
private long getMessageDiff(MessageExt msg){
	try {
		long offset = msg.getQueueOffset();//消息自身的offset
		String maxOffset = msg.getProperty(MessageConst.PROPERTY_MAX_OFFSET);//当前最大的消息offset
		long diff = Long.parseLong(maxOffset)-offset;//消费当前消息时积压了多少消息未消费
		return diff;
	} catch (Exception e) {
		return 0;
	}
}
 
Example 9
Source File: ConsumeMessageConcurrentlyService.java    From RocketMQ-Master-analyze with Apache License 2.0 5 votes vote down vote up
public void resetRetryTopic(final List<MessageExt> msgs) {
    final String groupTopic = MixAll.getRetryTopic(consumerGroup);
    for (MessageExt msg : msgs) {
        String retryTopic = msg.getProperty(MessageConst.PROPERTY_RETRY_TOPIC);
        if (retryTopic != null && groupTopic.equals(msg.getTopic())) {
            msg.setTopic(retryTopic);
        }
    }
}
 
Example 10
Source File: ClientRemotingProcessor.java    From RocketMQ-Master-analyze with Apache License 2.0 5 votes vote down vote up
public RemotingCommand checkTransactionState(ChannelHandlerContext ctx, RemotingCommand request)
        throws RemotingCommandException {
    final CheckTransactionStateRequestHeader requestHeader = (CheckTransactionStateRequestHeader) request
        .decodeCommandCustomHeader(CheckTransactionStateRequestHeader.class);
    final ByteBuffer byteBuffer = ByteBuffer.wrap(request.getBody());
    final MessageExt messageExt = MessageDecoder.decode(byteBuffer);
    if (messageExt != null) {
        final String group = messageExt.getProperty(MessageConst.PROPERTY_PRODUCER_GROUP);
        if (group != null) {
            MQProducerInner producer = this.mqClientFactory.selectProducer(group);
            if (producer != null) {
                final String addr = RemotingHelper.parseChannelRemoteAddr(ctx.channel());
                producer.checkTransactionState(addr, messageExt, requestHeader);
            }
            else {
                log.debug("checkTransactionState, pick producer by group[{}] failed", group);
            }
        }
        else {
            log.warn("checkTransactionState, pick producer group failed");
        }
    }
    else {
        log.warn("checkTransactionState, decode message failed");
    }

    return null;
}
 
Example 11
Source File: MessageFilterImpl.java    From RocketMQ-Master-analyze with Apache License 2.0 5 votes vote down vote up
@Override
public boolean match(MessageExt msg) {
    String property = msg.getProperty("SequenceId");
    if (property != null) {
        int id = Integer.parseInt(property);
        if (((id % 10) == 0) && //
                (id > 100)) {
            return true;
        }
    }

    return false;
}
 
Example 12
Source File: ProcessQueue.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 4 votes vote down vote up
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;
}
 
Example 13
Source File: ProcessQueue.java    From RocketMQ-Master-analyze with Apache License 2.0 4 votes vote down vote up
public boolean putMessage(final List<MessageExt> msgs) {
    boolean dispatchToConsume = false;
    try {
        this.lockTreeMap.writeLock().lockInterruptibly();
        try {
            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()) {
                MessageExt messageExt = msgs.get(msgs.size() - 1);
                String property = messageExt.getProperty(MessageConst.PROPERTY_MAX_OFFSET);
                if (property != null) {
                    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;
}