davsclaus opened a new pull request, #30874: URL: https://github.com/apache/camel/pull/30874
JIRA: [CAMEL-26362](https://issues.apache.org/jira/browse/CAMEL-26362) (follow-up of CAMEL-16039, batching in the sjms consumer) ## Problem The sjms batching consumer was not `ShutdownAware`, so Camel's graceful shutdown only saw the route's inflight exchanges. The buffered messages of a batch that was not routed yet were invisible to it: - With `AUTO_ACKNOWLEDGE`, the buffered (already acknowledged) messages were routed only during the stop of the consumer, after the graceful shutdown had stopped waiting, within the 10 seconds shutdown wait of the consumer's executor. A batch that took longer was interrupted and lost. With `batchInterval=0`, nothing routed them earlier. - With `transacted=true` / `CLIENT_ACKNOWLEDGE`, a batch could start (size reached, or interval elapsed while suspended) right after the graceful shutdown found nothing inflight. The stop then closed the session under it, and the batch was redelivered and routed again. ## Change - `SjmsConsumer` implements `ShutdownAware` (camel-sjms2 inherits it, as `Sjms2Endpoint extends SjmsEndpoint`). `deferShutdown` returns `false`, so the consumer is suspended first, as before. `getPendingExchangesSize()` returns the messages that the batch listener container still routes: the batch being routed, plus the buffered messages of an `AUTO_ACKNOWLEDGE` session. Without batching it returns 0, so nothing changes there. - `BatchConsumerWorker`, while the container is suspended or stopping: - `AUTO_ACKNOWLEDGE`: routes its partial batch right away, so the graceful shutdown waits for it (up to its own timeout) and does not leave it to the stop. - `transacted` / `CLIENT_ACKNOWLEDGE`: starts no batch. The buffered messages are routed after a resume, or rolled back and redelivered after a stop, as before. The pending count of a batch that is due is published before the worker checks the suspended state, so a shutdown that suspends the consumer at the same moment still sees that batch. - The "Batch consuming" section of the component docs now says how the graceful shutdown handles batches. The catalog copy is regenerated. ## Tests - `camel-sjms` `BatchConsumerGracefulShutdownTest` (in-VM Artemis): - AUTO_ACK, `batchInterval=0`, 3 of 5 messages buffered: the route is stopped while the processor blocks. The test checks that the partial batch is routed while the consumer is **Suspended**, that it counts as 3 pending, that `stopRoute` waits for it, and that all 3 messages arrive. **Fails on main** with `expected: <Suspended> but was: <Stopping>`: the batch was routed during the consumer stop, where it was interrupted after the 10 s executor wait. - Transacted: a batch in progress when the route is stopped completes and is committed, and it is not redelivered after a restart. - `camel-sjms2` `BatchConsumerGracefulShutdownTest`: the same AUTO_ACK case through `sjms2:`. - camel-sjms: 245 tests, 0 failures (5 skipped). The existing `BatchConsumerStopStartTest` cases ("partial batch not drained on stop" for tx / client-ack) still pass. `Batch*Test` passed 3 times with `-Dcamel.surefire.forkCount=8`. - camel-sjms2: 29 tests, 0 failures, run against this camel-sjms through a scratch local repo. ## Upgrade notes None: batching (CAMEL-16039) is new in 4.24 and has not been released yet. _Claude Code on behalf of davsclaus_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- 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]
