Сводка. Я делаю, как это решено в Настройка потребителя RabbitMQ в приложении ASP.NET Core но мой потребитель Rabbit онлайн, если я делаю веб-запрос, если я запускаю IIS и не запускаю запрос браузера, потребитель Rabbitне запускаетсяКто-нибудь знает почему?Может ли веб-приложение выполнять работу веб-приложения и службы Windows или это плохая идея?
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
...
services.AddSingleton<RabbitListener>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseRabbitListener();
...
}
}
public static class ApplicationBuilderExtentions
{
//the simplest way to store a single long-living object, just for example.
private static RabbitListener _listener { get; set; }
public static IApplicationBuilder UseRabbitListener(this IApplicationBuilder app)
{
_listener = app.ApplicationServices.GetService<RabbitListener>();
var lifetime = app.ApplicationServices.GetService<IApplicationLifetime>();
lifetime.ApplicationStarted.Register(OnStarted);
//press Ctrl+C to reproduce if your app runs in Kestrel as a console app
lifetime.ApplicationStopping.Register(OnStopping);
return app;
}
private static void OnStarted()
{
foreach (var o in LogOptions.Options)
_listener.NewRouteAdd(o.QueueString);
_listener.Register();
}
private static void OnStopping()
{
_listener.Deregister();
}
}