检查MSMQ消息的状态和结果 [英] Check the status and result of MSMQ message

查看:138
本文介绍了检查MSMQ消息的状态和结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用RESTfull Web服务,该服务执行以下操作:

  1. 在POST请求中,它将启动一个长期运行的任务.它将MSMQ的消息排队,在Windows服务托管的应用程序中处理.它返回HTTP状态代码202 Accepted以及我们排队的作业的ID.
  2. 客户端应用程序使用我们刚刚排队的作业的ID连续轮询服务(使用GET). MSMQ客户端完成任务后,应返回操作结果.如果不是,它将返回202接受,并带有下一次推荐轮询的适当到期日期.

我的问题是:如何实现从MSMQ到Web服务的通信?具体来说,我的Web服务如何知道MSMQ客户端是否处理了消息?

我的第一个方法是在SQL数据库中有一个作业"表,该表将包含一个JobId,一个指示作业是否完成以及计算结果的标志.然后,MSMQ应用程序将在完成作业时将其写入此表,而Web服务将根据每个请求在数据库中查询作业的状态.我不太喜欢这种方法,因为我的Web服务否则不会使用SQL Server-作业的结果是幂等的(但很耗时),而且我不打算保存以任何方式返回的数据.

我想知道是否有更惯用的方法来解决此问题,因为这是我第一次处理一般的MSMQ或消息队列.

解决方案

通过在您的流程中引入一个不同步的步骤,无论您是否乐意进入

I'm wondering if there is more idiomatic approach to this problem, as it's the first time I'm dealing with MSMQ or message queues in general.

By introducing an asychronous step into your process you have, willingly or not, entered the realm of eventual consistency.

There are inherent drawbacks with this approach, one of which is that it becomes necessary to continually check for convergence if the caller requires knowledge of system consistency being restored.

That is not to say I disagree with your approach, but if you're using vanilla MSMQ you need to be aware of the ramifications of doing so. MSMQ on it's own gives you none of the message exchange semantics you would expect from a service bus type platform, which would give you more options about how to handle your current perceived problem.

For example, if you could "reply" back to the sender via msmq (by using something like NServiceBus) then you could use some kind of server push technology like WebApi with SignalR to alert the client in realtime without the need to persist to DB.

An alternative would be to lose the asynchronous step, and replace it with a synchronous call, which would be feasible if the offline process completed quickly enough.

However, such approaches are complicated at best and your current solution is much simpler in my opinion.

这篇关于检查MSMQ消息的状态和结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆