Question

I'm trying to build an event driven Azure Queue where a event is to fired every time a message is put in the Azure Queue. With AzureXplorer I see that the messages are put in the Azure Queue properly but the CloudQueueClient.ResponseReceived Event never fires. I'm using Azure V1.4. This is the code from my Worker role:

public class WorkerRole : RoleEntryPoint
{
    public override void Run()
    {            
        while (true)
        {
            Thread.Sleep(10000);

        }
    }

    public override bool OnStart()
    {
        // Set the maximum number of concurrent connections 
        ServicePointManager.DefaultConnectionLimit = 12;

        var queuDataSource = new AzureQueueDataSource();
        queuDataSource.GetCloudQueueClient().ResponseReceived +=new EventHandler<ResponseReceivedEventArgs>(WorkerRole_ResponseReceived);


        // For information on handling configuration changes
        // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.
        return base.OnStart();
    }

    void WorkerRole_ResponseReceived(object sender, ResponseReceivedEventArgs e)
    {
        var i = 1;  // Breakpoint here never happends
    }
}
Was it helpful?

Solution

Windows Azure Queues need to be polled for new messages. See SDK samples or code here for examples on how to query queues for new messages.

Quick list of things to take into account:

  1. Because polling is counted as a transaction in Windows Azure, you will be paying for those.
  2. It is usually better to implement some kind of retry mechanism if no messages are found (e.g. exponential back-off, etc)
  3. It is usually good to retrieve messages in batches (less round trips, less transactions, etc)
  4. Remember that messages can be delivered more than once (plan for duplicate messages)
  5. Use the "dequeuecount" property to deal with "poison messages".

There's plenty of coverage on all these. See the documentation/samples in the link above. This article is pretty good too: http://blogs.msdn.com/b/appfabriccat/archive/2010/12/20/best-practices-for-maximizing-scalability-and-cost-effectiveness-of-queue-based-messaging-solutions-on-windows-azure.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top