EasyNetQ with asp.net web api as subscriber

十年热恋 提交于 2019-11-28 08:37:16

问题


I have to implement a asp.net web api which acts as a subscriber to rabbitMQ. The windows service is going to publish message to the web api services. There will be more than one instance of web api running on production enviornment. I am not sure how to open up the subscriber channel on web api and keep it open untill the IIS restarts. There will be one publisher and several consumer.

Can anyone please guide with some sample code to start with?

Any help will hugely appreciated


回答1:


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.

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.

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.



来源:https://stackoverflow.com/questions/25565769/easynetq-with-asp-net-web-api-as-subscriber

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!