try to refactor Kafka and add supports for RabbitMQ ...
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
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
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user