4

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 Answer 1

8

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.

Sign up to request clarification or add additional context in comments.

7 Comments

Excellent reply. just to the point. Thanks very much for the reply. I need to open the subscription in web api on IIS because it acts as a push service for rest of the application. When you say during application_end dispose of objects you mean the subscriberbus.Dispose?
Also does ll subscribers with the same objecttype i.e. bus<mymessage>.subscribe("localhost") will get the message when publisher publish with the same object type?
Yes, EasyNetQ routes by message type, so subscribers of a type will get all published messages of that type.
and subscriber.dispose() does all the magic when application ends? or I need to do anything else?
You need to bus.Dispose(); when your application exits. That will shut down all the consumers (subscribers) too.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.