1

We have a requirement to provide an API endpoint which reports the health of various external dependencies. One of these is an Azure Service Bus. By health we simply need to know if the service is available and responding to connections.

Our application already starts up a service bus endpoint on startup and uses this to publish messages to its queue. However, it looks like the only way I can test this endpoint's health would be to actually publish a message to the queue and check for errors. I'd rather not do this because having to clean up these message later feels like overkill.

My other idea was to use a dedicated class to create a new endpoint and start it. Then stop it again if there are no errors, as below. And do this each time I need to check the health.

// Build the service bus configuration - connection string etc.
var configuration = _configurationBuilder.Configure(_settings);

IEndpointInstance serviceBusEndpoint = null;

try
{
    serviceBusEndpoint = await Endpoint.Start(configuration);

    return true;
}
catch
{
    return false;
}
finally
{
    if (serviceBusEndpoint != null)
    {
        await serviceBusEndpoint.Stop();
    }
}

However, I suspect this may be a less efficient approach. Is there a better/correct way to achieve this aim?

Tom Troughton
  • 3,941
  • 2
  • 37
  • 77
  • Did you consider setting up [monitoring activity log alerts on service notifications](https://learn.microsoft.com/en-us/azure/monitoring-and-diagnostics/monitoring-activity-log-alerts-on-service-notifications) ? The [pricing](https://azure.microsoft.com/en-us/pricing/details/monitor/) seems reasonable and provides vast majority of options from sms/email -> azure app push notifications/webhooks. To be honest I didn't try this approach, so hard for me to comment if this is better approach. – Michael Jan 25 '18 at 15:40
  • Thanks, it's an interesting idea. However, my task is to provide a realtime status of various external services on demand. It may be possible to use these activity alerts to inform this but it'd never quite be a live status. I'm still interested in a specific answer to my question but thank you for helping me think outside the box. – Tom Troughton Jan 25 '18 at 15:47
  • Is `Endpoint.Start` your abstraction around Azure Service Bus or a framework of some sort? – Sean Feldman Jan 25 '18 at 22:17
  • Endpoint is part of the NServiceBus assembly – Tom Troughton Feb 01 '18 at 10:36
  • I am considering using https://learn.microsoft.com/en-us/dotnet/api/microsoft.servicebus.messaging.topicclient.schedulemessageasync?view=azure-dotnet, ...although if I were to Schedule a message hours in advance and then Cancel that message, that would constitute two billable operations, I guess at as operations are low cost it may not be a concern. – Darren Jun 04 '18 at 06:46

0 Answers0