Azure / azure-sdk-for-java

This repository is for active development of the Azure SDK for Java. For consumers of the SDK we recommend visiting our public developer docs at https://docs.microsoft.com/java/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-java.
MIT License
2.31k stars 1.97k forks source link

[BUG] Event Hub and Service Bus Producers should attempt to create a connection on send #27520

Closed conniey closed 1 year ago

conniey commented 2 years ago

Currently, if a connection is not reopened within the retry policy, the entire producer client is useless. However, it should be that we try to create a connection whenever a send operation is invoked and apply the retry policy to that case. If there exists a current connection, we'll reuse that.

We'll need to double-check this for the ServiceBusReceiverClient and ServiceBusReceiverAsyncClient as well.

ServiceBusSenderAsyncClient sender = builder.buildClient();

try {
// Just block here for the sake of the snippet.
   sender.sendMessage(message).block();
} catch (Exception e) {
   // The send operation timeout due to a network issue that lasts 10 minutes (past the retry policy).
   // So you'll get an exception when you block.
}

// Sometime later (like 10 or 30 minutes), the sender tries to send but the sender is no longer usable. 
// In other languages, when users invoke the send operation, that's when the sender will check whether 
// or not there is an active connection.
// If there is an active connection, it uses that to send.
// If there is _not_ an active connection, it tries to create a new one.
// This way, the same sender client can be used instead of having to create a new one.
sender.sendMessage(message2);
Toniotti commented 2 years ago

I'am having a similar problem using Spring JmsTemplate.

After about 10 minutes of inactive in a queue it can't send any more messages.

I'am using "spring-cloud-azure-starter-servicebus-jms" 4.0.0 and spring-boot 2.5.5

The stack trace presents this error:

org.springframework.jms.core.JmsTemplate.lambda$send$3(JmsTemplate.java:586)
    at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:504)
    ... 58 common frames omitted
    Caused by: org.apache.qpid.jms.provider.ProviderException: The link 'G3:51701296:qpid-jms:sender:ID:99e3893e-e039-4587-a868-2828cd2aa461:1:99:1:QUEUE_NAME' is force detached. Code: publisher(link4205569). Details: AmqpMessagePublisher.IdleTimerExpired: Idle timeout: 00:10:00. [condition = amqp:link:detach-forced]

Is there any solutions or workarounds for this?

liukun-msft commented 2 years ago

Hi @Toniotti Thanks for reporting that. Because you are using "spring-cloud-azure-starter-servicebus-jms", can you open up a new issue with detailed information, like how to reproduce? you can tag that issue with azure-spring-servicebus.

Toniotti commented 2 years ago

Hi @liukun-msft

I opened a new issue here #28754 (couldn't figure out how to put the label you asked for, i'am not used to github.)

conniey commented 1 year ago

Fixed via #33224