Azure / azure-service-bus-java

☁️ Java client library for Azure Service Bus
https://azure.microsoft.com/services/service-bus
MIT License
58 stars 57 forks source link

Azure event hub connection is closed error #420

Open meteor1016 opened 2 years ago

meteor1016 commented 2 years ago

I see something like the following error while using azure event hub to send event message. But as I see in the azure portal, the metric shows that the event message is sent to the event hub.

" Error{condition=amqp:connection:forced, description='The connection was inactive for more than the allowed 300000 milliseconds and is closed by container 'LinkTracker'. TrackingId:00000000000000000000000000000000000_G21, SystemTracker:gateway5, Timestamp:2019-03-06T17:32:00', info=null} "

As I read from the azure doc (https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-amqp-troubleshoot), it said "You see the following error on the AMQP connection when all links in the connection have been closed because there was no activity (idle) and a new link hasn't been created in 5 minutes."

The doc also said "You can avoid them by making send/receive calls on the connection/link, which automatically recreates the connection/link."

On another similar reported issue in https://github.com/Azure/azure-service-bus-java/issues/280, it appears that the above error log is only a reflection that the connection is being automatically closed, and so it is not actually an error.

On the other hand, I once tried that if I call the close() method in EventHubProducerClient (by refer to sample code in https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-java-get-started-send), this error seems not appear again.

However, if doing so, when every time need to send the event, it will mean need to create a new EventHubProducerClient. I'm not sure if this may create another problem (like time required to create the new EventHubProducerClient, and memory consumption) if creating a new EventHubProducerClient for every send event, as there can be many events to send.

So I would like to know, will the above error lead to any issue ?

And what should be the best practice regarding the use of EventHubProducerClient, is it to create a new EventHubProducerClient for every event sending ?

sharmando commented 2 months ago

https://github.com/Azure/azure-service-bus-java/issues/280#issuecomment-2071312651

It is a bug. However, yes: Creating and closing the producer each time you need it is a simple workaround. Not ideal, not the best at scale, but it will allow the system to work past a few minutes