[ 
https://issues.apache.org/jira/browse/CAMEL-26361?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18146150#comment-18146150
 ] 

Ramu commented on CAMEL-26361:
------------------------------

### Technical Investigation Update – Azure SDK Support for Asynchronous Session 
Processing

Further investigation indicates that the root of this issue is the interaction 
between Camel's asynchronous route processing and the callback contract of the 
Azure Service Bus session processor.

**Current limitation**

Camel uses Azure's `ServiceBusProcessorClient` for session-enabled consumers. 
Its message-processing callback uses a synchronous 
`Consumer<ServiceBusReceivedMessageContext>` contract.

When Camel dispatches a message to an asynchronous route, the callback returns 
after the exchange has been submitted to Camel's asynchronous processor, not 
after the exchange has actually completed.

Consequently, the Azure SDK may consider the message handler finished while 
Camel is still processing the exchange. The session processor's 
`sessionIdleTimeout` can then expire while the exchange is in flight. This can 
close the active session receiver before Camel completes or settles the message.

Simply increasing `sessionIdleTimeout` is not a satisfactory production fix:

- A larger timeout may protect long-running exchanges, but can unnecessarily 
hold an otherwise idle session and delay processing other available sessions.
- A short timeout can close the session while Camel still has an exchange in 
flight.
- Using a second receiver to renew the same session is not safe because the 
session lock is exclusive and already owned by the processor.

**Upstream Azure SDK direction**

The Azure SDK team has introduced a new API, `ServiceBusProcessorAsyncClient`, 
with asynchronous message and error handlers that return 
`reactor.core.publisher.Mono<Void>`.

This API is designed for applications performing asynchronous or reactive 
processing. Unlike the existing `Consumer` callback, the returned `Mono` 
represents the actual message-processing lifecycle.

For session-enabled processing, this allows the SDK to:

- Track the lifetime of in-flight message handlers.
- Keep the session active while asynchronous processing and settlement are 
still in progress.
- Continue using SDK-managed session acquisition, lock renewal, concurrency 
management and recovery.
- Apply the session idle timeout when there are no pending handlers, allowing 
an idle session to be released and another session to be acquired without 
waiting for an unnecessarily long timeout.

The new API therefore addresses the underlying lifecycle mismatch instead of 
relying on a larger timeout or introducing custom session-receiver and 
lock-management logic.

**Why we should wait for a stable SDK release**

As of November 17, 2026, the latest stable `azure-messaging-servicebus` release 
is 7.19.1. The new `ServiceBusProcessorAsyncClient` API is currently documented 
in the 7.20.0-beta.1 unreleased development line.

Introducing a beta Azure SDK dependency into an Apache Camel production 
component solely to address this issue would add avoidable release and 
compatibility risks.

We should wait for the API to become available in a stable Azure SDK release, 
then integrate it through Camel's existing Service Bus client factory and 
consumer lifecycle.

**Proposed implementation**

Once the stable Azure SDK release is available:

1. Use the SDK's asynchronous session processor for internally created 
session-enabled consumers.
2. Adapt Camel's `AsyncProcessor` lifecycle so the returned reactive handler 
completes only after the Camel exchange and its settlement decision have 
completed.
3. Retain Azure SDK ownership of session acquisition, session-lock renewal, 
concurrency, recovery and receiver lifecycle.
4. Preserve existing component configuration and compatibility with 
user-supplied `processorClient` instances.
5. Add integration tests covering long-running asynchronous routes, session 
rollover after processing completes, settlement, processing failures and 
graceful shutdown.

**Conclusion**

A timeout-only adjustment does not reliably solve the issue without introducing 
undesirable session-availability behavior. Replacing the Azure processor with 
manually managed receivers would also duplicate responsibilities already 
handled by the SDK.

The preferred solution is to integrate the stable Azure asynchronous processor 
API, which provides the correct processing-lifecycle contract for Camel 
asynchronous routes while preserving the existing Azure SDK processor 
architecture.

**Proposed status: Waiting for the stable Azure SDK release containing 
`ServiceBusProcessorAsyncClient`.**

> camel-azure-servicebus - renew the session lock for session-enabled consumers 
> with async routes
> -----------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-26361
>                 URL: https://issues.apache.org/jira/browse/CAMEL-26361
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-azure-servicebus
>            Reporter: Claus Ibsen
>            Assignee: Ramu
>            Priority: Major
>             Fix For: 4.25.0
>
>
> CAMEL-23937 added Camel-managed lock renewal for the Service Bus consumer in 
> {{PEEK_LOCK}} mode. The Azure SDK's own renewal is tied to the 
> {{processMessage}} callback, which returns at once for an async route, so 
> {{maxAutoLockRenewDuration}} had no effect there.
> That fix covers only consumers without sessions. In 
> {{ServiceBusConsumer.doStart()}}, the {{LockRenewer}} is set up only when 
> {{!getConfiguration().isSessionEnabled()}}. With {{sessionEnabled=true}}, a 
> route that processes messages asynchronously can still lose the lock before 
> it completes or abandons the message, so the message is delivered again.
> Session-enabled queues and subscriptions lock the session, not the single 
> message, so the existing {{renewMessageLock()}} does not apply. Renewal needs 
> {{renewSessionLock()}} on a client bound to the session.
> h3. Proposal
> * Extend the {{LockRenewer}} (or add a session variant) to renew the session 
> lock of each session that has an exchange in flight, until 
> {{maxAutoLockRenewDuration}} is reached or the last exchange of that session 
> completes.
> * Use a receiver bound to the session that delivered the message, created 
> through {{ServiceBusClientFactory}} like the existing renewal client.
> * Keep the current behaviour when the user supplies their own 
> {{processorClient}}.
> h3. Tests
> A session-enabled consumer with an async route that takes longer than the 
> lock duration: the message is completed once and not redelivered. A unit test 
> for the renewer with a mocked client.
> _Filed by Claude Code on behalf of davsclaus_



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to