将 NServiceBus 与 Asp.Net MVC 2 结合使用
有没有办法将 NServiceBus 与 Asp.Net MVC 2 一起使用?我想将请求消息从 Asp.Net MVC2 应用程序发送到服务,该服务处理该消息并回复响应消息。有没有办法清楚地做到这一点?
Is there a way to using NServiceBus with Asp.Net MVC 2? I want to send a request message from a Asp.Net MVC2 Application to a Service, which handle the message and reply with a response message. is there a way to do this clearly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
NServiceBus 仅支持注册状态代码和整数的回调是有原因的。原因是您不应该使用 NServiceBus 进行同步请求/响应式通信,这些场景最好使用 Wcf、NNibernate、EF、Ado.net 等框架来解决。
您应该只考虑将 NSB 用于应用程序的异步部分喜欢将“命令”发送到后端服务进行处理。
可以在这里找到深入的解释:
http:// /andreasohlund.net/2010/04/22/messaging-shouldnt-be-used-for-queries
如果您仍然想使用 NSB 进行请求/响应,则必须使用消息处理程序来实现它:)获取更新 MVC 应用程序中某些缓存的响应。有了它,您就可以进行一些 ajax 风格的轮询来确定数据何时到达。
希望这有帮助!
There is a reason that NServiceBus only supports registering callback for status codes and ints. That reason is that you shouldn't use NServiceBus for sync request/response style communications, those scenarios is best solved with frameworks like Wcf, NNibernate , EF, Ado.net etc.
You should look at only use NSB for async parts of your application like to send off "commands" to backend services for processing.
An in depth explanation can be found here:
http://andreasohlund.net/2010/04/22/messaging-shouldnt-be-used-for-queries
If you still want to do request/response with NSB you'll have to work for it :) using a messagehandler for your response that updates some cache in your MVC app. With that in place you can do some ajax style polling to determine when the data arrives.
Hope this helps!
如果您确实想要这样做,请按以下步骤操作:
If you really want to do this, here's how:
如果这是一个新建项目,我强烈建议考虑使用命令查询分离模式,这将帮助您在逻辑上分离有关业务域(命令)中的更改状态的关注点和仅充当状态描述机制的查询。然后可以使用 WCF 实例在 NServiceBus 和查询中实现命令。
If this is a greenfield project, I would strongly recommend thinking about using Command Query Separation pattern which would help you logically separate concerns regarding that change state in the business domain (command) and queries which acts only as state description mechanism. Then Commands can be implemented in NServiceBus and Queries using WCF for instance.