Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EasyNetQ with asp.net web api as subscriber

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

like image 473
user1213831 Avatar asked Feb 12 '23 03:02

user1213831


1 Answers

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.

like image 167
Mike Hadlow Avatar answered Feb 23 '23 00:02

Mike Hadlow