You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
using System;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using EntrustSettle.Common;
|
|
|
|
|
using EntrustSettle.EventBus;
|
|
|
|
|
using EntrustSettle.EventBus.EventHandling;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
|
|
|
|
namespace EntrustSettle.Extensions.HostedService;
|
|
|
|
|
|
|
|
|
|
public class EventBusHostedService : IHostedService
|
|
|
|
|
{
|
|
|
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
|
|
private readonly ILogger<EventBusHostedService> _logger;
|
|
|
|
|
|
|
|
|
|
public EventBusHostedService(IServiceProvider serviceProvider, ILogger<EventBusHostedService> logger)
|
|
|
|
|
{
|
|
|
|
|
_serviceProvider = serviceProvider;
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task StartAsync(CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("Start EventBus Service!");
|
|
|
|
|
await DoWork();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Task DoWork()
|
|
|
|
|
{
|
|
|
|
|
var eventBus = _serviceProvider.GetRequiredService<IEventBus>();
|
|
|
|
|
eventBus.Subscribe<BlogQueryIntegrationEvent, BlogQueryIntegrationEventHandler>();
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task StopAsync(CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("Stop EventBus Service!");
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
}
|