Search in sources :

Example 1 with MessageOffset

use of com.hummer.rocketmq.consumer.plugin.support.offset.MessageOffset in project hummer-framework by hummer-team.

the class MessageHandlerHolder method builderEventData.

public Tuple.TupleTwo<List<MessageData<E>>, List<MessageOffset>> builderEventData(List<MessageExt> msgs, String group) {
    List<MessageData<E>> data = Lists.newArrayListWithCapacity(msgs.size());
    List<MessageOffset> offsets = Lists.newArrayListWithCapacity(msgs.size());
    for (MessageExt message : msgs) {
        // event data
        try {
            MessageData<E> messageData = createEventData(message);
            data.add(messageData);
        } catch (Exception e) {
            LOGGER.warn("topic {} message deserialize error ", message.getTopic(), e);
        }
        // queue offset
        MessageOffset offset = getMessageOffset(message, group);
        offsets.add(offset);
    }
    return new Tuple.TupleTwo<>(data, offsets);
}
Also used : MessageExt(org.apache.rocketmq.common.message.MessageExt) MessageData(com.hummer.message.common.MessageData) MessageOffset(com.hummer.rocketmq.consumer.plugin.support.offset.MessageOffset)

Example 2 with MessageOffset

use of com.hummer.rocketmq.consumer.plugin.support.offset.MessageOffset in project hummer-framework by hummer-team.

the class PullConsumer method setOffset.

private void setOffset(List<MessageExt> msgs) {
    for (MessageExt msg : msgs) {
        Tuple.TupleTwo<Boolean, Long> offset = offsetMap.get(msg.getQueueId());
        if (offset == null) {
            MessageOffset msgOffset = MessageOffset.loadMessageOffset(group, msg.getTopic(), msg.getQueueId());
            if (msgOffset != null) {
                offsetMap.put(msg.getQueueId(), new Tuple.TupleTwo<>(Boolean.TRUE, msgOffset.getOffset()));
                queueOffsetMap.put(msg.getQueueId(), msgOffset.getOffset());
                MessageOffset.seekOffsetWithMessage(msgOffset, msg, pullConsumer);
            }
        }
    }
    // reSet offset index
    if (MapUtils.isNotEmpty(queueOffsetMap)) {
        MessageOffset.reSetMessageExt(msgs, queueOffsetMap);
    }
}
Also used : MessageExt(org.apache.rocketmq.common.message.MessageExt) MessageOffset(com.hummer.rocketmq.consumer.plugin.support.offset.MessageOffset) Tuple(com.hummer.common.tuple.Tuple)

Aggregations

MessageOffset (com.hummer.rocketmq.consumer.plugin.support.offset.MessageOffset)2 MessageExt (org.apache.rocketmq.common.message.MessageExt)2 Tuple (com.hummer.common.tuple.Tuple)1 MessageData (com.hummer.message.common.MessageData)1