如何使用 MessageQueue 检测连接中断
我用 C# 编写的应用程序使用 .NET 中的 MessageQueue 类与另一个远程应用程序通信消息,并且在所有情况下 MessageQueue 应始终与远程消息队列“连接”(存在心跳)。如果它没有“连接”,则表明出现了问题,我的应用程序将需要执行一些操作,例如更新事件日志。
MessageQueue
类中是否有方法可用于检测此类连接中断?
My application written in C# makes use of the MessageQueue
class in .NET for communicating messages with another remote application and the MessageQueue should always be "connected" (heartbeat present) with the remote messageQueue under all circumstances. If it is not "connected", then it signals that something is wrong and my application will need to perform some actions such as updating an event log.
Is there a method in the MessageQueue
class that can be used to detecting such breaks in connection?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
消息队列在很大程度上是为了防止断开连接而设计的。并且支持通过多台机器进行路由。因此,它无法检查是否存在实时连接。如果这是一个要求,您可能不应该考虑 MSMQ,TCP 将是一个更好的老鼠陷阱。
您可以考虑请求确认消息和超时。虽然那是被动的。心跳是可能的,但请务必使用单独的非事务性队列。
Message queuing is very much designed to survive disconnects. And supports routing through several machines. As such, it doesn't have a way to check if a live connection is present. You probably shouldn't consider MSMQ if that's a requirement, TCP would be a better mouse trap.
You could consider asking for acknowledgment of your message and time-out on that. That's passive though. A heart beat is possible, but be sure to use a separate, non transactional queue.