문제

We are having MVC application which reads data from MSMQ. We are trying to find out a way to read message from queue and remove it from queue only if user has done a successful operation on the queue. The message should remain in the queue until user completes the processing, the message should not be available to anyone else until the user who is processing the message object has finished the operation.

Is there a property for a Message object to be set as Peeked which will not allow reading of this message again until ether it is put back into the queue or removed from the queue?

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

도움이 되었습니까?

해결책

It sounds like you need to use your queue(s) in transactional mode. Then, your client can receive a message, process it, and then commit the transaction, at which point the message will be finally dequeued. While the transaction is active, however, 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

다른 팁

The Queue is the right idea. Your approach of "leave it in the queue, locked, but still kind-of-available" is wrong.

You may need multiple queues.

  1. Process A enqueues something in Queue 1

  2. Process B dequeues from Queue 1 and starts work.

    • If B is successful, that's it.

    • Otherwise, it gets queued somewhere else (perhaps the same queue, or perhaps Queue 2) for follow-up work.

If it went back into Queue 1, B will find it again, eventually. If it went to another Queue, then another process does cleanup, logging, error fixup or whatever, possibly putting something back in Queue 1.

A Queue isn't a database -- there's nothing stateful (no "don't look at me, I'm being processed").

A Queue is transient storage. Someone writes, someone else reads, and that's it.


If you want reliability, read this: 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 feature of the queue, not your application. You can do a "recoverable read". It's a transaction that's part of the queue API.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top