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_r407841661
 
 

 ##########
 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();
 
 Review comment:
   The REST API provided by the broker contains the number of messages that 
have not yet been acknowledged. However, I don't think it's realistic in terms 
of performance to access the broker's REST API every time the WebSocket proxy 
receives a cumulative ack.
   ```sh
   $ curl -s 
http://dev-broker01.pulsar.xxx.yahoo.co.jp:8080/admin/v2/persistent/massakam/test/t1/internalStats
 | jq .
   
   {
     "entriesAddedCounter": 10,
     "numberOfEntries": 30,
     "totalSize": 1760,
     "currentLedgerEntries": 10,
     "currentLedgerSize": 520,
     "lastLedgerCreatedTimestamp": "2020-04-14T10:47:40.829+09:00",
     "waitingCursorsCount": 2,
     "pendingAddEntriesCount": 0,
     "lastConfirmedEntry": "2823032:9",
     "state": "LedgerOpened",
     "ledgers": [
       {
         "ledgerId": 2820274,
         "entries": 20,
         "size": 1240,
         "offloaded": false
       },
       {
         "ledgerId": 2823032,
         "entries": 0,
         "size": 0,
         "offloaded": false
       }
     ],
     "cursors": {
       "pulsar.repl.dev2": {
         "markDeletePosition": "2823032:9",
         "readPosition": "2823032:10",
         "waitingReadOp": true,
         "pendingReadOps": 0,
         "messagesConsumedCounter": 10,
         "cursorLedger": 2823043,
         "cursorLedgerLastEntry": 1,
         "individuallyDeletedMessages": "[]",
         "lastLedgerSwitchTimestamp": "2020-04-14T10:47:40.831+09:00",
         "state": "Open",
         "numberOfEntriesSinceFirstNotAckedMessage": 1,
         "totalNonContiguousDeletedMessagesRange": 0,
         "properties": {}
       },
       "sub1": {
         "markDeletePosition": "2820274:19",
         "readPosition": "2823032:10",
         "waitingReadOp": true,
         "pendingReadOps": 0,
         "messagesConsumedCounter": 0,
         "cursorLedger": 2823042,
         "cursorLedgerLastEntry": 0,
         "individuallyDeletedMessages": "[]",
         "lastLedgerSwitchTimestamp": "2020-04-14T10:52:11.384+09:00",
         "state": "Open",
         "numberOfEntriesSinceFirstNotAckedMessage": 11,
         "totalNonContiguousDeletedMessagesRange": 0,
         "properties": {}
       }
     }
   }
   ```

----------------------------------------------------------------
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

Reply via email to