I'm writing some functionality that responds to an Azure Service Bus Queue. This currently polls on a specified queue and OnMessage triggers a callback to a method in the original class that calls it:
partial class Class1
{
private void BeginProcessing()
{
serviceBusHelper.Listen(QueueType.Inbound, HandleTransaction);
}
private bool HandleTransaction(BrokeredMessage message)
{
...
}
}
And then the service bus helper class:
public class ServiceBusHelper : IServiceBusHelper
{
ManualResetEvent CompletedResetEvent = new ManualResetEvent(false);
public void Listen(QueueType queue, Action<BrokeredMessage> callback)
{
switch (queue)
{
case QueueType.Inbound:
inboundClient.OnMessage(message =>
{
try
{
callback(message);
}
catch (Exception ex)
{
...
}
CompletedResetEvent.WaitOne();
});
break;
...
}
}
It is connecting correctly to the azure service bus queue and retrieving the message, however the callback never seems to actually trigger. What I'm trying to achieve is a service that will continuously respond to an OnMessage event, trigger a new worker (from within class1) despite the OnMessage actually being triggered from the ServiceBusHelper class.