question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Service Bus] Detect connection status

See original GitHub issue

Right now it does not seem possible to detect the connection state with Azure Service Bus. There is no property that indicates if we are connected or if there is some connectivity issue (or other issue, like subscription deleted etc).

Describe the solution you’d like I want a boolean property on the SubscriptionClient that tells me if it is connected. And I want an event on connection changes, i.e. Connected and Disconnected.

Describe alternatives you’ve considered The alternative I’m using now uses Reflection, which is fragile. It does a little bit like this:

var subscriptionClient = new SubscriptionClient(connStr, topic, subscription, ReceiveMode.PeekLock);
var conn = subscriptionClient.ServiceBusConnection;
FaultTolerantAmqpObject<AmqpConnection> connectionManager = (FaultTolerantAmqpObject<AmqpConnection>)typeof(ServiceBusConnection).GetProperty("ConnectionManager", BindingFlags.Instance | BindingFlags.NonPublic).GetMethod.Invoke(conn, null);
var amqpConnection = await connectionManager.GetOrCreateAsync(TimeSpan.FromSeconds(2));
var amqpSessionSettings = new AmqpSessionSettings { Properties = new Fields() };
while (true)
{
    var session = amqpConnection.CreateSession(amqpSessionSettings);
    var connected = false;
    try
    {
        await session.OpenAsync(TimeSpan.FromSeconds(2));
        await session.CloseAsync(TimeSpan.FromSeconds(2));
        connected = true;
    }
    catch (TimeoutException)
    {
    }
    Console.WriteLine(connected);
    Thread.Sleep(2000);
}

Additional context I’ll use this to inform the healthcheck of a container on a Kubernetes environment.

We shouldn’t need to have to use reflection. And I get that the library is resilient and will reconnect. But I need to setup scaling, alerts and other infrastructure based on the fact that there is a worker doing what it is supposed to be doing. If for some reason a container gets disconnected from Service Bus, I need to know, I might setup infrastructure that will recreate it, setup alarms, etc. My queues/topics might be filling up, and I don’t get to react to it.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:19
  • Comments:70 (41 by maintainers)

github_iconTop GitHub Comments

2reactions
JoshLove-msftcommented, Sep 27, 2021

That’s a good point - I think we could also have a property that indicates how many messages are currently being processed.

1reaction
JoshLove-msftcommented, Sep 27, 2022

@scgbear, yes we are planning on taking a different approach here. @lmolkova do you have any timelines for when the metrics work will begin for .NET?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Check Connection with Azure service bus using Java SDK
One of the way to check whether connection is established or not is sending and receiving message from service bus. Once you have...
Read more >
Troubleshooting guide for Azure Service Bus
When there are intermittent connectivity issues, run the following command to check if there are any dropped packets. This command tries to ...
Read more >
Monitoring Azure Service Bus data reference
See Monitoring Azure Service Bus for details on collecting and analyzing monitoring data for Azure Service Bus.
Read more >
How to check connection to Azure Services?
The example below shows how to test connectivity to Azure Service Bus. Test-NetConnection -ComputerName watchdog.servicebus.windows.net -Port ...
Read more >
Azure Service Bus and its Complete Overview
Azure Service Bus is a messaging service on cloud used to connect any applications, devices, and services running in the cloud.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found