我的 asp.net mvc 4 应用程序没有 send/publish 到 rabbitmq
My asp.net mvc 4 application does not send/publish to rabbitmq
我有一个应用程序,一个 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"});
};
...
}
提前致谢
不要将它放在 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();
}
我有一个应用程序,一个 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"});
};
...
}
提前致谢
不要将它放在 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();
}