Back to blog

Azure Service Bus: how to Delay a Message Being Sent to the Queue

Blog

From time to time you come across a situation where you need to do a little code fakery, I recently had a similar situation where I needed to raise a BrokeredMessage but delay it by a couple of minutes.

THE PROBLEM

I needed to publish a BrokeredMessage to the azure service bus once a process had been completed by a 3rd party application. The 3rd party application always took a couple of minutes to run but had no completed event I could hook into.

THE SOLUTION WITH SERVICE BUS

The solution was incredibly simple, the BrokeredMessage class comes with a property called ScheduledEnqueueTimeUtc. This property allows us to set a date in the future when the message should be enqueued, effectively creating a delay.

EXAMPLE CODE

SAMPLE EVENT

BROKEREDMESSAGE WITH ADDED DELAY

PUBLISH MESSAGE USING TOPIC CLIENT

PULLING IT ALL TOGETHER

SUMMARY

So to conclude, even though it always feels a little bit hacky adding message enqueue delays, at least it is really easy to do with the Azure Service Bus BrokeredMessage class.

Cloud Futures AI Business

Leave a Reply

Your email address will not be published. Required fields are marked *

The browser you're using is out of date. Please update for better security, speed and experience on this site.