0

I am developing a website to be deployed in Azure. Right now I am using an Azure Queue to send emails to users. I am checking the Queue for received messages after each 60 seconds by sleeping the current Thread.

My problem is I do not want to wait the Thread and wait for 60 seconds, instead I want to trigger the message sending functionality when the Queue actually receives a message. I found the mechanism of Service Bus Topics/Subscriptions but I want to know whether I can implement the same Subscription mechanism with Azure Queues (without using Topics/Subscriptions). Is this possible? Can an Azure Queue listen to something so it can run only when a message is received to the Queue. I certainly don't want to sleep the Thread.

Thank you.

Thilok Gunawardena
  • 924
  • 5
  • 22
  • 44

1 Answers1

1

The question of Azure Queues supporting long-polling has been asked before - which is why I marked this as a duplicate.

Regarding thread-sleep: Not sure why you certainly don't want to sleep a thread to listen on a queue. It can be a separate thread, meaning you're not tying up other processes. And... as long as there are messages on the queue, you don't need to sleep between calls to GetMessage() - just keep reading until the queue is empty.

Also: Why wait 60 seconds? Start with 1 second, maybe exponential backoff to, say, 16 seconds, then stay there? Barely costs anything to check every few seconds (a penny per 100K transactions). This is a very common pattern, even with multiple role instances running.

David Makogon
  • 69,407
  • 21
  • 141
  • 189