Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Listen to Queue (Event Driven no polling) Service-Bus / Storage Queue

I'm trying to figure out how can I listen to an events on a queue (especially an enqueue event).

Say I have a Console Application and a Service Bus Queue/Topic, how can I connect to the Queue and wait for a new message ?

I'm trying to achieve this without While(true) and constant polling, I'm trying to do it more in a quite listener way something like a socket that stay connected to the queue.

The reason I don't want to use polling is that I understand that its floods the server with requests, I need a solution that will work on great loads.

Thank you.

I gave very basic example for the simplicity of the question but My real situation are a bit more complex:

I've Web-API that send messages that are needed to be process to a Worker Role using Service Bus Queue.

I need somehow to know when the Worker has been processed the message. I want the Worker to send a message to the queue alerting that the Web API has processed the message, but now I need to make the Web-API "sit" and wait for a response of the Worker back, that lead me to my question:

How can I listen to a queue constantly and without polling (because there is a lot of instances that will pooling and its will create a lot of requests that maybe its best to avoid.

like image 829
Ron Avatar asked Oct 26 '15 00:10

Ron


1 Answers

Use the Azure WebJobs SDK - it has triggers to monitor queues and blobs with simple code like:

public static void Main()
{
    JobHost host = new JobHost();
    host.RunAndBlock();
}

public static void ProcessQueueMessage([QueueTrigger("webjobsqueue")] string inputText, 
    [Blob("containername/blobname")]TextWriter writer)
{
    writer.WriteLine(inputText);
}

There is a great tutorial at What is the Azure WebJobs SDK.

like image 103
viperguynaz Avatar answered Sep 21 '22 02:09

viperguynaz