43 lines
1.2 KiB
C#
43 lines
1.2 KiB
C#
using EgwCoreLib.Lux.Data.Services;
|
|
using EgwCoreLib.Lux.Data;
|
|
|
|
namespace Lux.API.Services
|
|
{
|
|
public class RedisSubscriberService : BackgroundService
|
|
{
|
|
#region Public Constructors
|
|
|
|
public RedisSubscriberService(IConfiguration config, RedisSubscriptionManager subManager, ExternalMessageProcessor processor)
|
|
{
|
|
_subManager = subManager;
|
|
_processor = processor;
|
|
_config = config;
|
|
subChannel = _config.GetValue<string>("ServerConf:SubChannel") ?? "";
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Protected Methods
|
|
|
|
protected override Task ExecuteAsync(CancellationToken stoppingToken)
|
|
{
|
|
_subManager.Subscribe(subChannel, async (ch, msg) =>
|
|
{
|
|
await _processor.HandleResultMessageAsync($"{ch}", $"{msg}");
|
|
});
|
|
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private readonly IConfiguration _config;
|
|
private readonly ExternalMessageProcessor _processor;
|
|
private readonly RedisSubscriptionManager _subManager;
|
|
private readonly string subChannel = "";
|
|
|
|
#endregion Private Fields
|
|
}
|
|
} |