gnodet opened a new pull request, #31133:
URL: https://github.com/apache/camel/pull/31133
## Summary
Add Camel-managed session lock renewal for session-enabled consumers in
`PEEK_LOCK` mode
with async routes. Session-enabled queues/subscriptions lock the _session_
rather than
individual messages, so the existing `LockRenewer` (which calls
`renewMessageLock()`) does
not apply. This PR adds `SessionLockRenewer`, a periodic task that calls
`renewSessionLock()` on a session-bound `ServiceBusReceiverAsyncClient` for
every session
that has at least one exchange in flight.
## Root Cause
`ServiceBusConsumer.doStart()` set up `LockRenewer` only when
`!isSessionEnabled()`.
Session-enabled async routes could therefore lose the session lock before
the route
finished processing, causing the message to be redelivered.
The Azure SDK's own `maxAutoLockRenewDuration` is tied to the
`processMessage` callback,
which returns immediately for async routes, so SDK-side renewal has no
effect in this case.
## Fix
- Added `SessionLockRenewer` inner class in `ServiceBusConsumer` that:
- Accepts a session-bound `ServiceBusReceiverAsyncClient` per active
session via
`ServiceBusSessionReceiverAsyncClient.acceptSession()`.
- Renews the session lock every `LOCK_RENEW_INTERVAL_SECONDS` (5 s) when
fewer than
`LOCK_RENEW_BEFORE_EXPIRY_SECONDS` (20 s) remain.
- Shares one receiver across concurrent in-flight exchanges of the same
session (ref-counted),
closing it when all exchanges of that session complete.
- Stops renewal and closes the receiver when `maxAutoLockRenewDuration`
elapses.
- Retries transient errors (`ServiceBusException.isTransient()`) on the
next run;
stops on non-transient errors (e.g. lost session lock).
- `ServiceBusClientFactory.createServiceBusSessionReceiverAsyncClient()`
added to build
the outer session receiver client needed for `acceptSession()`.
- `doStop()` / `doShutdown()` cancel the renewer and close all open session
receivers.
## Tests
New unit tests in `ServiceBusConsumerTest` cover:
- `SessionLockRenewer` created only when session-enabled + PEEK_LOCK +
positive max duration + no custom client.
- Session receiver accepted once per session; `renewSessionLock()` called
when lock is near expiry.
- Session-bound receiver shared across multiple in-flight exchanges of the
same session (ref-count).
- Receiver closed when the last exchange of a session completes.
- Transient renewal errors are retried on the next run.
- Non-transient errors (session lock lost) stop renewal.
- `doStop()` closes all open session receivers.
- Stop/start cycle creates a fresh session receiver client.
Fixes CAMEL-26361
---
_Hermes Agent (Claude Sonnet 4.6) on behalf of Guillaume Nodet_
--
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]