50 lines
1.5 KiB
C#
50 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Logging;
|
|
using RabbitMQ.Client;
|
|
using xCommons.Extensions;
|
|
using xEventService.Configuration;
|
|
using xEventService.Extensions;
|
|
using xExceptions.Constants;
|
|
|
|
namespace xEventService.Providers
|
|
{
|
|
/// <summary>
|
|
/// an Abstract Kafka Consumer Service ...
|
|
/// </summary>
|
|
public class XRabbitMQConsumerServiceBase : BackgroundService
|
|
{
|
|
protected readonly IModel channel;
|
|
protected readonly IConnection connection;
|
|
protected readonly XEventServiceConfiguration configuration;
|
|
protected readonly ILogger<XRabbitMQConsumerServiceBase> logger;
|
|
|
|
public XRabbitMQConsumerServiceBase(
|
|
XEventServiceConfiguration configuration,
|
|
ILogger<XRabbitMQConsumerServiceBase> logger
|
|
)
|
|
{
|
|
//
|
|
this.logger = logger;
|
|
this.configuration = configuration;
|
|
|
|
//
|
|
// Validate ...
|
|
if (!configuration.IsValid() ||
|
|
!configuration.RabbitMQ.IsValid() ||
|
|
configuration.Broker != Constants.XEventBroker.XRabbitMQ
|
|
)
|
|
{
|
|
XException.InvalidConfiguration.Throw();
|
|
}
|
|
}
|
|
|
|
public abstract Task HandleMessageAsync(
|
|
XEventMessage message,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
}
|
|
} |