且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用 asp.net web api 作为订阅者的 EasyNetQ

更新时间:2023-12-01 21:06:16

通常 RabbitMQ 订阅不适用于 IIS 托管应用程序,因为您无法控制应用程序何时运行.IIS 将根据需要回收、停止和启动应用程序.

Generally RabbitMQ subscriptions don't work well with IIS hosted applications because you have no control over when the application is running. IIS will recycle, stop and start the app as it sees fit.

如果必须这样做,请打开到 RabbitMQ 的连接并在应用程序启动时开始订阅,例如在 Global.asax.cs 中,并确保在关闭时正确处理所有内容.

If you must do it, open the connection to RabbitMQ and start subscribing when the application starts, in Global.asax.cs for example, and make sure to dispose of everything properly when it closes.

您***为订阅构建一个 Windows 服务,然后写入 IIS 托管的 Web 服务可以访问的共享存储,或者在 Windows 服务中自托管 API.

You are far better off building a windows service for the subscription and either writing to a shared store that the IIS hosted web service can access, or alternatively self-hosting the API inside the windows service.