[BUG] Connections to service bus dropped and recreated regularly when using ServiceBusSessionReceiverAsyncClient bean
See original GitHub issueDescribe the bug I am creating a Spring Bean with an ServiceBusSessionReceiverAsyncClient so that I can reuse this in my REST API based application.
@Bean
public ServiceBusSessionReceiverAsyncClient apiMessageQueueIntegrator() {
return new ServiceBusClientBuilder()
.transportType(AmqpTransportType.AMQP_WEB_SOCKETS)
.connectionString(connectionString)
.sessionReceiver()
.receiveMode(ServiceBusReceiveMode.RECEIVE_AND_DELETE)
.queueName(queueName)
.buildAsyncClient();
}
In an @RestController, I do the following:
@Autowired
ServiceBusSessionReceiverAsyncClient apiMessageQueueIntegrator;
.
.
.
@GetMapping("/simulateapicall")
public ResponseEntity<?> processApiCall() {
.
.
.
Mono<ServiceBusReceiverAsyncClient> receiverMono = apiMessageQueueIntegrator.acceptSession(sessionid);
Disposable subscription = Flux.usingWhen(receiverMono,
receiver -> receiver.receiveMessages(),
receiver -> Mono.fromRunnable(() -> receiver.close()))
.subscribe(message -> {
// Process message.
logger.info(String.format("Message received from queue. Session id: %s. Contents: %s%n", message.getSessionId(),
message.getBody()));
}, error -> {
logger.info("Queue error occurred: " + error);
});
.
.
.
// After having received message
subscription.dispose();
}
(NB! I am sending/receiving only one message per session. I use this in an request/reply scheme.)
This code logic works fine, but when running load testing, I see that the link to the service bus, is closed regularly and reopened. It seems that the connection to the service bus lives for 1-2 seconds, and is then closed and a new connection is opened. This causes issues because my sessions (from acceptSession), gets broken or fails when trying to be created.
It might seem that the dropped connections happens more if I increase the load towards the application.
Exception or Stack Trace I have attached a file that shows the typical lifecycle of the connection. From when it is created to when it is dropped. My log files typically consists of many such lifecycles as connections are dropped and recreated.
To Reproduce Create similar code to what I have described. Run jMeter to put load on.
Code Snippet See bug description.
Expected behavior I expect the connection to the service bus to be kept up and not terminated.
Screenshots N/A
Setup (please complete the following information):
- OS: Azure app service (Linux, Java 11)
- Library/Libraries: azure-messaging-servicebus:7.5.0
- Java version: 11
- App Server/Environment: Azure app service
- Frameworks: Spring Boot
Additional context N/A
Information Checklist Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report
- Bug Description Added
- Repro Steps Added
- Setup information Added
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:37 (14 by maintainers)
Top Related StackOverflow Question
can you please increase the priority of this task? We have been waiting for a solution for a long time…
Hi, few days ago I’ve updated to the latest ServiceBus SDK (com.azure:azure-messaging-servicebus:jar:7.8.0). The situation seems to have been slightly changed, now after ~5 minutes of idle a exception is raised. Anyway after the exception the app is still working because it seems a new connection is opened under the hood.
Here is how I create the async client:
And then how I subscribe new message with Quarkus Mutiny:
This is the raised exception: