0

There is an Azure Service Bus Queue with the session property enabled (Requires session = true)

The consumer is a native Azure Java "client" (com.azure:azure-messaging-servicebus)

The problem is that there is no way with this Java client to close the session manually. As a result, when maxConcurrentSessions reached the whole application stop receiving messages until the session lock timeout reached.

So the main question here is: How can we close a session manually using the Java client?


Might help:

In this article there is an example how to do it but is on C#. It seems that there is a "session" object used to close the session. I was not able to reproduce it in the Java client.

https://devblogs.microsoft.com/premier-developer/ordering-messages-in-azure-service-bus/

Code of the client init:

new ServiceBusClientBuilder()
        .connectionString(queueConnectionString)
        .sessionProcessor()
        .queueName(queueName)
        .maxConcurrentSessions(5)
        .maxConcurrentCalls(2)
        .processMessage(this::processMessage)
        .processError(this::processError)
        .maxAutoLockRenewDuration(Duration.ofMinutes(30))
        .disableAutoComplete()
        .buildProcessorClient();
  • Are these helpful? [QueueSessionTests.java](https://github.com/Azure/azure-sdk-for-java/blob/3f31d68eed6fbe11516ca3afe3955c8840a6e974/sdk/servicebus/microsoft-azure-servicebus/src/test/java/com/microsoft/azure/servicebus/QueueSessionTests.java) and [SessionHandlerOptions.java](https://github.com/Azure/azure-sdk-for-java/blob/3f31d68eed6fbe11516ca3afe3955c8840a6e974/sdk/servicebus/microsoft-azure-servicebus/src/main/java/com/microsoft/azure/servicebus/SessionHandlerOptions.java) and – Ecstasy Aug 08 '22 at 04:44
  • [More details about prefetchCount and maxConcurrentSessions in ServiceBusClientBuilder.ServiceBusSessionProcessorClientBuilder Class](https://github.com/Azure/azure-sdk-for-java/issues/25293) – Ecstasy Aug 08 '22 at 04:44

0 Answers0