Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Consume AMQP messages from ASP.net MVC 4 using RabbitMQ

Let's say that I want to consume AMQP messages from ASP.net MVC 4 using RabbitMQ. I store an object in System.Web.HttpContext.Current.Application which internally uses an instance of BackgroundWorker to listen for messages (the listener is created in Global.asax.cs)

Is this a good way to implement this operation or should I use a static class / singleton? I am inexperienced in ASP.net MVC so I am uncertain. Maybe ASP.net MVC 4 is not the best platform choose? What would you recommend?

The goal is to be able to monitor/log message traffic, kill/create/configure consumers at will from a web interface.

This is my first stackoverflow post as I believe in good research. But, this time I would like to hear from other people, thx :)

like image 690
user2140283 Avatar asked Oct 04 '22 19:10

user2140283


1 Answers

An ASP.NET application makes a poor RabbitMQ subscriber in my opinion. You are far better off implementing your subscriber as a windows service.

  1. This excellent post by Phil Haack gives some good reasons why should think twice about using the BackgroundWorker for any serious service.
  2. It means that you can monitor and maintain your subscriber independently of your web application. You can use all the out-of-the-box tools that windows gives you - task monitor, perf monitor - to understand how your service is behaving.
  3. You can scale your subscriber independently of your web application. You might need only one instance of your web application, but two of your subscriber. Having them as separate processes gives you that kind of finer grained control.
like image 169
Mike Hadlow Avatar answered Oct 13 '22 12:10

Mike Hadlow