为什么不建议使用MassTransit在Web应用程序中托管接收端点?

问题描述:

我正在研究ASP.NET MVC 5应用程序(基于nopCommerce).我想使用MassTransit与另一个用于库存管理,计费等的应用程序进行通信.如果我可以将接收端点直接添加到Web应用程序中,而不必为此创建Windows服务,则将更加容易.但是 MassTransit文档表示不建议这样做,也没有任何解释为什么会这样.

I am working on an ASP.NET MVC 5 application (based on nopCommerce). I want to use MassTransit to communicate with another application that is used for inventory management, billing, etc. It would be easier if I could add receive endpoints directly into the web application and not have to create a Windows service for that. But the MassTransit documentation says it is not recommended and there is no explanation as to why that is.

Web应用程序中的MassTransit

通常在网站上配置总线以发布事件, 发送命令,以及进行请求/响应对话. 不建议托管接收端点和持久性使用者 (使用上面显示的服务).

Configuring a bus in a web site is typically done to publish events, send commands, as well as engage in request/response conversations. Hosting receive endpoints and persistent consumers is not recommended (use a service as shown above).

有人知道其背后的原因吗?在Web应用程序中添加接收端点是否不安全?他们会无法正常工作吗?

Does anyone know the reasoning behind it? Is it not safe to add receive endpoints in a web application? Will they not work properly?

不建议在Web应用程序中托管终结点,因为Web应用程序通常由于各种原因而重新启动.这些原因通常不在应用程序本身的控制范围之内.

Hosting endpoints in a web application is not recommended because web applications often restart for various reasons. These reasons are typically outside the control of the application itself.

强烈建议使用独立的Windows服务,只要使用Application_StartApplication_End方法正确启动和停止了总线,就可以了,如果没有其他可用选项.

While using a standalone Windows service is highly recommended, as long as the bus is properly started and stopped using the Application_Start and Application_End methods, it can be okay if you have no other options available.