68 lines
1.9 KiB
C#
68 lines
1.9 KiB
C#
using System;
|
|
using Microsoft.Extensions.Logging;
|
|
using xCommons.Extensions;
|
|
using xCommons.Providers;
|
|
using xEventService.Configuration;
|
|
using xEventService.Constants;
|
|
using xEventService.Extensions;
|
|
using xExceptions.Constants;
|
|
|
|
namespace xEventService.Providers
|
|
{
|
|
/// <summary>
|
|
/// Base Event Consumer Service ...
|
|
/// </summary>
|
|
public abstract class XBaseEventConsumerBackgroundService : XResumableBackgroundService
|
|
{
|
|
/// <summary>
|
|
/// Consumed Topic Messages ...
|
|
/// </summary>
|
|
protected readonly string topic;
|
|
|
|
/// <summary>
|
|
/// Allowed Senders ...
|
|
/// </summary>
|
|
public readonly string[] allowedSenders;
|
|
|
|
/// <summary>
|
|
/// Allowed Actions ...
|
|
/// </summary>
|
|
public readonly string[] allowedActions;
|
|
|
|
/// <summary>
|
|
/// Configuration ...
|
|
/// </summary>
|
|
protected readonly XEventServiceConfiguration configuration;
|
|
|
|
protected XBaseEventConsumerBackgroundService(
|
|
string[] allowedActions,
|
|
string[] allowedSenders,
|
|
IServiceProvider serviceProvider,
|
|
XEventServiceConfiguration configuration,
|
|
ILogger<XResumableBackgroundService> logger,
|
|
string topic = XEventServiceConstants.XDefaultTopic
|
|
) : base(
|
|
logger: logger,
|
|
serviceProvider: serviceProvider
|
|
)
|
|
{
|
|
//
|
|
// Validate Actions ...
|
|
if (!allowedActions
|
|
.IsAllowedCollection() ||
|
|
!allowedSenders
|
|
.IsAllowedCollection() ||
|
|
!configuration.IsValid()
|
|
)
|
|
{
|
|
XException.InvalidArgs.Throw();
|
|
}
|
|
|
|
//
|
|
this.topic = topic;
|
|
this.configuration = configuration;
|
|
this.allowedActions = allowedActions;
|
|
this.allowedSenders = allowedSenders;
|
|
}
|
|
}
|
|
} |