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


##########
components/camel-box/camel-box-component/src/main/java/org/apache/camel/component/box/BoxConsumer.java:
##########
@@ -75,15 +104,67 @@ public void onEvent(BoxEvent event) {
 
     @Override
     public void onNextPosition(long position) {
-        // noop
+        nextPosition = position;
+        lock.lock();
+        try {
+            // the event stream works again
+            restartDelay = RESTART_DELAY;
+        } finally {
+            lock.unlock();
+        }
     }
 
+    /**
+     * Called by the event stream when it fails (for example when Box cannot 
be reached for a while). The event stream
+     * has stopped itself by then and is never started again by the Box SDK: 
listen again after a delay, else the
+     * consumer stays started without receiving any event.
+     */
     @Override
     public boolean onException(Throwable e) {
         
getExceptionHandler().handleException(RuntimeCamelException.wrapRuntimeCamelException(e));
+        scheduleRestart();
         return true;
     }
 
+    private void scheduleRestart() {
+        lock.lock();
+        try {
+            if (!isRunAllowed() || restartExecutor == null) {
+                return;
+            }
+            long delay = restartDelay;
+            restartDelay = Math.min(restartDelay * 2, MAX_RESTART_DELAY);
+            LOG.info("The Box event stream stopped, listening for events again 
in {} ms", delay);
+            restartExecutor.schedule(this::restart, delay, 
TimeUnit.MILLISECONDS);
+        } finally {
+            lock.unlock();
+        }
+    }
+
+    private void restart() {
+        lock.lock();
+        try {
+            if (!isRunAllowed()) {
+                return;
+            }
+            Long position = nextPosition != null ? nextPosition : 
startingPosition();
+            apiProxy.stopListening();
+            apiProxy.listen(this, position);
+            LOG.info("Listening for Box events again from position {}", 
position != null ? position : "now");
+        } catch (Exception e) {
+            // such as Box still not reachable when the event stream starts
+            LOG.debug("Cannot listen for Box events again", e);
+            scheduleRestart();

Review Comment:
   Accepted as by design: the consumer keeps trying, with a backoff up to 60 s. 
A failure of the event stream goes to the exception handler in `onException` 
before each restart, so revoked credentials show there; only a failure of 
`listen()` inside `restart()` itself is logged at DEBUG and retried.
   
   _Claude Code on behalf of Claus Ibsen_



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