Croway commented on PR #30800:
URL: https://github.com/apache/camel/pull/30800#issuecomment-7187396267

   Thanks Claus. I rebased on main (it conflicted with CAMEL-27534 in 
`JmsConsumer`) and addressed all six points.
   
   **1. A slow message on a healthy broker**
   
   - **JMS:** with the default configuration this does not happen. Camel always 
gives the simple container a task executor (its own cached pool) unless 
`taskExecutor` is set. Spring's `SimpleMessageListenerContainer` then hands 
each message to that executor from the JMS client's listener, so 
`Connection.stop()` does not wait for the route. I checked it: with 
`consumerType=Simple`, a message blocked for 25 s and a suspend from another 
thread, the suspend returned in 1 ms, the container was kept, and the message 
was not redelivered.
   - **JMS with a synchronous `taskExecutor` (`SyncTaskExecutor`):** here your 
scenario is real, and slightly worse than a WARN. Artemis waits for the 
`onMessage` in progress up to its `onMessageCloseTimeout`, which is 10 s, the 
same as the bound. Once the bound fires, the background destroy closes the 
session while the route is still processing, so a message longer than about 20 
s fails its ack and is redelivered. Instead of documenting it, with 
`consumerType=Simple` and `SyncTaskExecutor` the consumer now keeps waiting 
while messages are being processed, and applies the full bound after the last 
one. `EndpointMessageListener` counts the `onMessage` calls in progress and the 
ones completed for this. With a thread pool (Camel's own or one of the 
application), nothing changes, as the JMS client does not wait for the route 
there. The test is `testSuspendWaitsForTheMessageThatTheJmsClientProcesses`.
   - **Rabbit:** Spring AMQP waits for in-flight deliveries itself, up to the 
container's `shutdownTimeout`, and then force-closes the channels. So the bound 
is now the component's `shutdownTimeout` plus `shutdownAwaitTermination`. A 
slow message no longer trips it, and when the WARN fires, the extra time was 
spent waiting for the broker to answer the cancel. The test is 
`suspendWaitsForTheMessageThatIsProcessed`. The `shutdownTimeout` caveat is 
gone from the upgrade guide.
   
   **2. Lower limit:** both components now use `Math.max(100, 
shutdownAwaitTermination)`, with a test in each module. Agreed on a dedicated 
option; I'd leave that for a follow-up ticket.
   
   **3. Bound per consumer:** `graceful-shutdown.adoc` now says the bound is 
per consumer and what happens after the shutdown timeout. I also changed what 
happens after the interrupt. Once the waiting thread is interrupted, the 
consumer still waits up to 100 ms for the stop. So the healthy consumers that 
the cancelled task suspends afterwards (CAMEL-26555) keep their container 
without a WARN, and only the blocked ones give up. The interrupt flag is 
restored. The test is 
`suspendByAnInterruptedThreadWaitsForAListenerContainerThatStopsAtOnce`.
   
   **4. One pattern for both components:** JMS now uses the Rabbit pattern 
(`CompletableFuture` + `AtomicBoolean`), and `ListenerContainerStop` is gone. 
When a suspend gives up, the detached container is handed to the background 
stop through a second `CompletableFuture`, which destroys it once the stop 
returns. JMS also has its own cached `JmsStopListenerContainer` pool now, like 
Rabbit, instead of sharing `AsyncStartStopListener`. After the rebase this was 
necessary: the CAMEL-27534 tests hold every task of that pool, and a suspend 
should not queue behind an async start anyway. A shared helper can come later.
   
   **5. Rabbit docs:** the paragraph is now after the Spring Boot snippet and 
the prefetch paragraph, and it describes the new bound and the listener-thread 
case.
   
   **6. Suspend from a Rabbit listener thread:** I had not covered it, so I 
checked the Spring AMQP 4.2.0 source. Neither SMLC nor DMLC treats the listener 
thread specially: `shutdownAndWaitOrCallback` waits up to `shutdownTimeout` for 
the in-flight delivery, whichever thread stops the container. That delivery is 
the caller itself, so before this PR a suspend from a listener thread already 
waited the whole `shutdownTimeout` inline. Now that the bound includes the 
`shutdownTimeout`, the stop on the component thread always ends in time, so no 
inline case is needed. An inline stop would also lose the bound when the broker 
does not answer. The tests are `suspendFromTheListenerThread` (DMLC and SMLC) 
and an IT against a real broker that checks the `shutdownTimeout` wait and that 
no WARN is logged. The IT also shows that once `shutdownTimeout` expires, 
Spring AMQP closes the channel of the message that triggered the suspend, so 
the broker redelivers it after the resume. That happened inlin
 e before this PR as well, and the component page now says so.
   
   **Rebase (CAMEL-27534):** after a suspend that gave up, `doResume` now 
creates and starts a new container. This branch used to log "Probably there was 
a timeout during the Suspend operation". A `startOnResume` flag, guarded by 
`containerLock`, records this, and it survives a failed async start. The detach 
also resets `listenerContainerCounted` and `asyncStartPending`. A container 
that `getListenerContainer()` creates meanwhile is initialized and counted by 
the resume, and a stop releases only containers that were counted. The tests of 
#30825 (`JmsAsyncStartListenerSuspendResumeTest`, 
`JmsAsyncStopListenerRestartTest`) pass.
   
   _Claude Code on behalf of Croway_
   


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