@Override public int compareTo(MessageIdImpl other) { return ComparisonChain.start().compare(this.ledgerId, other.ledgerId).compare(this.entryId, other.entryId) .compare(this.getPartitionIndex(), other.getPartitionIndex()).result(); }
@Override public void redeliverUnacknowledgedMessages(Set<MessageIdImpl> messageIds) { for (ConsumerImpl c : consumers) { Set<MessageIdImpl> consumerMessageIds = new HashSet<>(); messageIds.removeIf(messageId -> { if (messageId.getPartitionIndex() == c.getPartitionIndex()) { consumerMessageIds.add(messageId); return true; } return false; }); c.redeliverUnacknowledgedMessages(consumerMessageIds); } }
/** * Clear the internal receiver queue and returns the message id of what was the 1st message in the queue that was * not seen by the application */ private MessageIdImpl clearReceiverQueue() { List<Message> currentMessageQueue = new ArrayList<>(incomingMessages.size()); incomingMessages.drainTo(currentMessageQueue); if (!currentMessageQueue.isEmpty()) { MessageIdImpl nextMessageInQueue = (MessageIdImpl) currentMessageQueue.get(0).getMessageId(); MessageIdImpl previousMessage = new MessageIdImpl(nextMessageInQueue.getLedgerId(), nextMessageInQueue.getEntryId() - 1, nextMessageInQueue.getPartitionIndex()); return previousMessage; } else if (lastDequeuedMessage != null) { // If the queue was empty we need to restart from the message just after the last one that has been dequeued // in the past return lastDequeuedMessage; } else { // No message was received or dequeued by this consumer. Next message would still be the startMessageId return (MessageIdImpl) startMessageId; } }
public int removeMessagesTill(MessageIdImpl msgId) { readLock.lock(); try { int currentSetRemovedMsgCount = currentSet.removeIf(m -> ((m.getLedgerId() < msgId.getLedgerId() || (m.getLedgerId() == msgId.getLedgerId() && m.getEntryId() <= msgId.getEntryId())) && m.getPartitionIndex() == msgId.getPartitionIndex())); int oldSetRemovedMsgCount = oldOpenSet.removeIf(m -> ((m.getLedgerId() < msgId.getLedgerId() || (m.getLedgerId() == msgId.getLedgerId() && m.getEntryId() <= msgId.getEntryId())) && m.getPartitionIndex() == msgId.getPartitionIndex())); return currentSetRemovedMsgCount + oldSetRemovedMsgCount; } finally { readLock.unlock(); } }
@Override protected CompletableFuture<Void> doAcknowledge(MessageId messageId, AckType ackType) { checkArgument(messageId instanceof MessageIdImpl); if (getState() != State.Ready) { return FutureUtil.failedFuture(new PulsarClientException("Consumer already closed")); } if (ackType == AckType.Cumulative) { return FutureUtil.failedFuture(new PulsarClientException.NotSupportedException( "Cumulative acknowledge not supported for partitioned topics")); } else { ConsumerImpl consumer = consumers.get(((MessageIdImpl) messageId).getPartitionIndex()); return consumer.doAcknowledge(messageId, ackType); } }
builder.setPartition(messageId.getPartitionIndex()); builder.setLedgerId(messageId.getLedgerId()); builder.setEntryId(messageId.getEntryId());