是否可以将 GetAllMessages 和 Purge 作为事务处理
在开始处理队列中的消息之前,我需要收集所有“旧”消息并处理它们。之后我进入读取/处理循环。
GetAllMessages
将返回消息数组,但是它不会将它们从队列中删除。 Purge
将从队列中删除所有消息。我需要将两者作为交易来完成。这可能吗?
Before I start processing the messages in the queue i need to harvest off all the "old" messages and deal with them. After that I get into my read/process loop.
GetAllMessages
will return an array of messages, howerver it does not remove them from the queue. Purge
will remove all messages from the queue. I need to do both as a transaction. Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您需要在(重新)启动服务后处理剩余消息。
我实现的解决方案只是使用可配置的接收超时来控制处理循环,因此您的服务不需要担心队列的状态 - 它将处理那里的任何内容。
这是一个简单的 C# 示例,
我计划将超时延长为动态,因为每次超时异常抛出时都会增加超时,并在处理消息后立即重置它。
使用 MSMQ 编程最佳实践中给出了简短的介绍,尽管它没有不完全支持我提出的解决方案。
进一步挖掘后,我发现了 一个建议 MSMQ 激活的答案,但我自己还没有尝试过。
It sounds like you need to deal with processing leftover messages after (re)starting a service.
A solution I implemented simply uses a configurable receive timeout to control the processing loop so your service doesn't need to bother about the state of the queue - it will process whatever is there.
Here's a simple C# sample
I planned to extend the timeout to be dynamic in that it would increase the timeout every time the timeout exception throws and reset it as soon as a message is processed.
A short introduction is given in Programming best Practices with MSMQ although it doesn't exactly back my proposed solution.
Digging a little more I found an answer proposing MSMQ Activation which I didn't try out myself yet.