[Service Bus] Detect connection status
See original GitHub issueRight 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:
- Created 4 years ago
- Reactions:19
- Comments:70 (41 by maintainers)
Top GitHub Comments
That’s a good point - I think we could also have a property that indicates how many messages are currently being processed.
@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?