在ASP.NET Core 2.x应用程序中,我想在托管服务(特别是BackgroundService
)中设置所有RabbitMQ(EasyNetQ)订阅。到目前为止,看起来像这样...
Startup.cs
public class MessagingService : BackgroundService
{
private readonly AutoSubscriber subscriber;
public MessagingService(IBus bus)
{
this.subscriber = new AutoSubscriber(bus, Assembly.GetExecutingAssembly().GetName().Name);
}
protected override Task ExecuteAsync(CancellationToken stoppingToken)
{
...
}
}
MessagingService.cs
ExecuteAsync
现在,我的问题是... protected override Task ExecuteAsync(CancellationToken stoppingToken)
{
return Task.Factory.StartNew(() => subscriber.SubscribeAsync(Assembly.GetExecutingAssembly()));
}
中应该包含什么内容?假设我只想打电话给void subscriber.SubscribeAsync(Assembly[])
。是否需要将其包装在任意任务中?
protected override Task ExecuteAsync(CancellationToken stoppingToken)
{
subscriber.SubscribeAsync(ExecutingAssembly)
return Task.CompletedTask;
}
对于在应用程序启动时运行一次的方法而言,这是否过于矫kill过正?我应该只运行它并返回完成的任务吗?
blabla.aa
cc.oiwerwer
asfd.Dd.asoiwer
这里有规则吗?有什么我应该分析的东西吗?