Search code examples
c#msmq

Delayed Invocation of a Message Queue?


I have an existing application that sends messages from one process to another via a queued transport. I'd like to morph how the messages are processed by giving a delay in when they're processed and have the queue act more as a priority queue with the message that should be acted upon first at the top of the queue.

IE:

At Time 0 Message A is sent to the queue with a delay of 15 minutes. 5 Minutes later Message B is sent to the queue with a delay of 10 minutes. The service processing the queue then crashes and isn't restarted for 15 more minutes. When the queue starts processing again message B will be on top followed by message A.

Is there anything like this in the C# / MSMQ / .NET ecosystem?


Solution

  • If you are doing cloud programming on Windows Azure, there is a way to handle this. Simply specify the visibilitytimeout to Put Message.

    From http://msdn.microsoft.com/en-us/library/windowsazure/dd179346.aspx :

    visibilitytimeout=

    Optional. If specified, the request must be made using an x-ms-version of 2011-08-18 or newer. If not specified, the default value is 0. Specifies the new visibility timeout value, in seconds, relative to server time. The new value must be larger than or equal to 0, and cannot be larger than 7 days. The visibility timeout of a message cannot be set to a value later than the expiry time. visibilitytimeout should be set to a value smaller than the time-to-live value.

    The optional visibility timeout specifies the time that the message will be invisible. After the timeout expires, the message will become visible. If a visibility timeout is not specified, the default value of 0 is used.