Search in sources :

Example 1 with KeyLongValue

use of org.apache.pulsar.common.api.proto.KeyLongValue in project pulsar by apache.

the class Consumer method messageAcked.

public CompletableFuture<Void> messageAcked(CommandAck ack) {
    this.lastAckedTimestamp = System.currentTimeMillis();
    Map<String, Long> properties = Collections.emptyMap();
    if (ack.getPropertiesCount() > 0) {
        properties = ack.getPropertiesList().stream().collect(Collectors.toMap(KeyLongValue::getKey, KeyLongValue::getValue));
    }
    if (ack.getAckType() == AckType.Cumulative) {
        if (ack.getMessageIdsCount() != 1) {
            log.warn("[{}] [{}] Received multi-message ack", subscription, consumerId);
        }
        if (Subscription.isIndividualAckMode(subType)) {
            log.warn("[{}] [{}] Received cumulative ack on shared subscription, ignoring", subscription, consumerId);
        }
        PositionImpl position = PositionImpl.EARLIEST;
        if (ack.getMessageIdsCount() == 1) {
            MessageIdData msgId = ack.getMessageIdAt(0);
            if (msgId.getAckSetsCount() > 0) {
                long[] ackSets = new long[msgId.getAckSetsCount()];
                for (int j = 0; j < msgId.getAckSetsCount(); j++) {
                    ackSets[j] = msgId.getAckSetAt(j);
                }
                position = PositionImpl.get(msgId.getLedgerId(), msgId.getEntryId(), ackSets);
            } else {
                position = PositionImpl.get(msgId.getLedgerId(), msgId.getEntryId());
            }
        }
        if (ack.hasTxnidMostBits() && ack.hasTxnidLeastBits()) {
            List<PositionImpl> positionsAcked = Collections.singletonList(position);
            return transactionCumulativeAcknowledge(ack.getTxnidMostBits(), ack.getTxnidLeastBits(), positionsAcked);
        } else {
            List<Position> positionsAcked = Collections.singletonList(position);
            subscription.acknowledgeMessage(positionsAcked, AckType.Cumulative, properties);
            return CompletableFuture.completedFuture(null);
        }
    } else {
        if (ack.hasTxnidLeastBits() && ack.hasTxnidMostBits()) {
            return individualAckWithTransaction(ack);
        } else {
            return individualAckNormal(ack, properties);
        }
    }
}
Also used : MessageIdData(org.apache.pulsar.common.api.proto.MessageIdData) InitialPosition(org.apache.pulsar.common.api.proto.CommandSubscribe.InitialPosition) Position(org.apache.bookkeeper.mledger.Position) PositionImpl(org.apache.bookkeeper.mledger.impl.PositionImpl) KeyLongValue(org.apache.pulsar.common.api.proto.KeyLongValue)

Aggregations

Position (org.apache.bookkeeper.mledger.Position)1 PositionImpl (org.apache.bookkeeper.mledger.impl.PositionImpl)1 InitialPosition (org.apache.pulsar.common.api.proto.CommandSubscribe.InitialPosition)1 KeyLongValue (org.apache.pulsar.common.api.proto.KeyLongValue)1 MessageIdData (org.apache.pulsar.common.api.proto.MessageIdData)1