@Override public void operationComplete(Future<Void> future) throws Exception { if (future.isSuccess()) { if (ackType == AckType.Individual) { unAckedMessageTracker.remove(msgId); // increment counter by 1 for non-batch msg if (!(messageId instanceof BatchMessageIdImpl)) { stats.incrementNumAcksSent(1); } } else if (ackType == AckType.Cumulative) { stats.incrementNumAcksSent(unAckedMessageTracker.removeMessagesTill(msgId)); } if (log.isDebugEnabled()) { log.debug("[{}] [{}] [{}] Successfully acknowledged message - {}, acktype {}", subscription, topic, consumerName, messageId, ackType); } ackFuture.complete(null); } else { stats.incrementNumAcksFailed(); ackFuture.completeExceptionally(new PulsarClientException(future.cause())); } } });
@Override protected CompletableFuture<Void> doAcknowledge(MessageId messageId, AckType ackType) { checkArgument(messageId instanceof MessageIdImpl); if (getState() != State.Ready && getState() != State.Connecting) { stats.incrementNumAcksFailed(); return FutureUtil.failedFuture(new PulsarClientException("Consumer not ready. State: " + getState())); } if (messageId instanceof BatchMessageIdImpl) { if (markAckForBatchMessage((BatchMessageIdImpl) messageId, ackType)) { // all messages in batch have been acked so broker can be acked via sendAcknowledge() if (log.isDebugEnabled()) { log.debug("[{}] [{}] acknowledging message - {}, acktype {}", subscription, consumerName, messageId, ackType); } } else { // other messages in batch are still pending ack. return CompletableFuture.completedFuture(null); } } // if we got a cumulative ack on non batch message, check if any earlier batch messages need to be removed // from batch message tracker if (ackType == AckType.Cumulative && !(messageId instanceof BatchMessageIdImpl)) { updateBatchAckTracker((MessageIdImpl) messageId, ackType); } return sendAcknowledge(messageId, ackType); }
stats.incrementNumAcksFailed(); ackFuture .completeExceptionally(new PulsarClientException("Not connected to broker. State: " + getState()));