0

I have an application, an asp.net mvc 4 application. I want to use rabbitmq with easynetq. In my local computer, it works perfectly. But in the production environment which is windows server 2012, it does not send any message.

I could not understand, why it does not work. In log message, nothing unusual. IIS and rabbitmq is in the same machine.

    protected void Application_Start()
    {
    ...
          using (var bus = RabbitHutch.CreateBus("host=localhost"))
          {
            bus.Publish(new SystemLog() { Code = "startapplication", Message = "nomessage" });
          }        
    ...
    }

    void Session_End(object sender, EventArgs e)
    {
      ...
            using (var bus = RabbitHutch.CreateBus("host=localhost"))
            {
                bus.Publish(new SystemLog() { Code = "sessionends", Message = "somenumber"});
            };
      ...
     }        

Thanks in advance

2
  • The "host" is changed according? Commented Dec 16, 2015 at 8:42
  • In both machine, development machine, and the prod. machine the same connection is used.(host=localhost) Commented Dec 16, 2015 at 8:48

1 Answer 1

2

Don't put it in a using statement, that will dispose the bus instance immediately when startup is complete, you want to keep the same instance during the life time of your application.

Instead save the instance somewhere (like a static variable), and dispose it in the application_end event, not session_end.

So more like this:

protected void Application_Start()
{
  _bus = RabbitHutch.CreateBus("host=localhost"))
  _bus.Publish(new SystemLog() { Code = "startapplication", Message = "nomessage" });
}

void Session_End(object sender, EventArgs e)
{
  _bus.Publish(new SystemLog() { Code = "sessionends", Message = "somenumber"});
}

protected void Application_End()
{
  if(_bus!=null)
    _bus.Dispose();
}
Sign up to request clarification or add additional context in comments.

Comments

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.