【问题标题】:My asp.net mvc 4 application does not send/publish to rabbitmq我的 asp.net mvc 4 应用程序不发送/发布到 rabbitmq
【发布时间】:2015-12-16 08:41:06
【问题描述】:

我有一个应用程序,一个 asp.net mvc 4 应用程序。我想将rabbitmq 与easynetq 一起使用。在我的本地计算机上,它运行良好。但是在windows server 2012的生产环境中,它不会发送任何消息。

我不明白,为什么它不起作用。在日志消息中,没有什么异常。 IIS和rabbitmq在同一台机器上。

    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"});
            };
      ...
     }        

提前致谢

【问题讨论】:

  • "host"改成根据?
  • 在机器、开发机器和产品中。机器使用相同的连接。(host=localhost)

标签: c# asp.net-mvc asp.net-mvc-4 rabbitmq easynetq


【解决方案1】:

不要把它放在 using 语句中,它会在启动完成后立即释放总线实例,您希望在应用程序的生命周期内保持相同的实例。

而是将实例保存在某处(如静态变量),并将其放置在 application_end 事件中,而不是 session_end 中。

所以更像这样:

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();
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-12
    • 2014-04-03
    • 1970-01-01
    相关资源
    最近更新 更多