Remove a message from the queue only if the user performs some operation

We have an MVC application that reads data from MSMQ. We are trying to figure out a way to read a message from the queue and remove it from the queue only if the user has completed a successful queue operation. The message must remain in the queue until the user completes processing, the message must not be available to anyone else, until the user who is processing the message object has completed the operation.

Is there a property on the Message object that needs to be set to Peeked that prevents this message from being read again until the ether is queued or removed from the queue?

We're not sure if using MSMQ is a good idea in this case?

+2


source to share


2 answers


It looks like you need to use your turn (s) in transactional mode. Your client can then receive the message, process it, and then commit the transaction, after which the message will be permanently canceled. However, while the transaction is active, other clients will not see the message — it will be held in reserve until the transaction completes or is aborted.

This MSDN article has a decent overview of usage patterns for reliable messaging with MSMQ:



http://msdn.microsoft.com/en-us/library/ms978430.aspx

+1


source


The queue is the right idea. Your approach to "leave it in queue, blocked but still not available" is incorrect.

You may need multiple queues.

  • Process A completes something in queue 1

  • Process B removes 1 from the queue and starts running.

    • If B succeeds, then it is.

    • Otherwise, it is queued somewhere else (possibly the same queue, or perhaps queue 2) for later work.

If it goes back to queue 1, B will find it again. If it went to a different queue, then another process is doing cleanup, logging, error correction, or something else, perhaps something is being returned to queue 1.

The queue is not a database - it's nothing in terms of state (no "don't look at me, I'm being processed").

A queue is temporary storage. Someone writes, someone reads, and that's it.




If you want reliability, read the following: http://msdn.microsoft.com/en-us/library/ms978430.aspx

And this: http://blogs.msdn.com/shycohen/archive/2006/02/20/535717.aspx

And this: http://www.request-response.com/blog/PermaLink,guid,03fb0e40-b446-42b5-ad90-3be9b0260cb5.aspx

Reliability is a function of the queue, not your application. You can do a "recoverable read". This is a transaction that is part of the queue API.

0


source







All Articles