massakam commented on a change in pull request #6680: [Issue
5979][pulsar-websocket] Add cumulative acknowledgement to websocket consumer
URL: https://github.com/apache/pulsar/pull/6680#discussion_r406702707
##########
File path:
pulsar-websocket/src/main/java/org/apache/pulsar/websocket/ConsumerHandler.java
##########
@@ -240,12 +242,27 @@ public void onWebSocketText(String message) {
// We should have received an ack
MessageId msgId =
MessageId.fromByteArrayWithTopic(Base64.getDecoder().decode(command.messageId),
topic.toString());
- consumer.acknowledgeAsync(msgId).thenAccept(consumer ->
numMsgsAcked.increment());
- if (!this.pullMode) {
- int pending = pendingMessages.getAndDecrement();
- if (pending >= maxPendingMessages) {
- // Resume delivery
- receiveMessage();
+ if ("cumulative".equals(command.ackType)) {
+ ConsumerStats cStats = consumer.getStats();
+ long ackDiff = cStats.getTotalMsgsReceived() -
cStats.getTotalAcksSent();
+
consumer.acknowledgeCumulativeAsync(msgId).thenAccept(consumer ->
numMsgsAcked.add(ackDiff));
+ if (!this.pullMode) {
+ int acked = (int) ackDiff;
+ IntBinaryOperator decrementFunction = (x, y) -> x - y;
+ int pending = pendingMessages.accumulateAndGet(acked,
decrementFunction);
Review comment:
It is suitable to use `getAndAccumulate()` instead of ` accumulateAndGet()`
here.
We must execute `receiveMessage()` in order to resume delivery of messages
to the client only if `pendingMessages` **before** the update is greater than
or equal to `maxPendingMessages`.
If `pendingMessages` is less than `maxPendingMessages`, then
`receiveMessage()` has already been called just after receiving a message from
the broker, and we don't need to execute it again here.
https://github.com/apache/pulsar/blob/918dc6842d09bc07478adb5fb099aa43f1d40f1b/pulsar-websocket/src/main/java/org/apache/pulsar/websocket/ConsumerHandler.java#L196-L200
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services