davsclaus commented on code in PR #28204:
URL: https://github.com/apache/camel/pull/28204#discussion_r4333715976


##########
components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsConsumer.java:
##########
@@ -262,28 +275,41 @@ private void setupJetStreamConsumer(String topic, String 
queueName) throws IOExc
             }
         }
 
-        private void runPullFetchLoop(JetStreamSubscription sub, 
CamelNatsMessageHandler messageHandler) {
+        private void runPullFetchLoop(
+                JetStreamSubscription subscription, CamelNatsMessageHandler 
messageHandler, ConsumerConfiguration cc) {
+            JetStreamSubscription sub = subscription;
             int batchSize = configuration.getPullBatchSize();
             Duration fetchTimeout = 
Duration.ofMillis(configuration.getPullFetchTimeout());
             while (NatsConsumer.this.isRunAllowed() && 
!Thread.currentThread().isInterrupted()) {
                 try {
                     List<Message> messages = sub.fetch(batchSize, 
fetchTimeout);
+                    if (messages.isEmpty() && consumerCheckDue() && 
consumerGone(sub)) {
+                        sub = consumerDeleted(sub, cc);
+                        continue;
+                    }

Review Comment:
   Not blocking, and main behaves the same today, but this PR makes it the 
intended state for a durable: when the consumer is gone, jnats ends each 
`fetch` at once on the 503 "no responders" status (`STATUS_TERMINUS` in 
`PullMessageManager`), so `fetch` returns an empty list right away instead of 
after `pullFetchTimeout` and the loop sends pull requests back to back. For an 
ephemeral consumer that lasts up to the 5 s consumer check; for a durable that 
is gone it lasts until someone creates it again, which may be never.
   
   Could the loop wait `pullFetchTimeout` before the next fetch while the 
consumer is known to be gone (for example while `durableGoneReported` is true), 
or whenever a fetch came back empty well before its timeout? The wait should 
end when the thread is interrupted, so stopping still works. A follow-up is 
fine too.



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to