add supports for ZeroMQ, XRabbitMQ, XKafka ...
This commit is contained in:
@@ -17,23 +17,17 @@ namespace xEventService.Providers
|
||||
/// <summary>
|
||||
/// RabbitMQ Producer Service Implementation ...
|
||||
/// </summary>
|
||||
public class XRabbitMQProducerService : IXRabbitMQProducerService
|
||||
public class XRabbitMQProducerService : XBaseEventProducerService, IXRabbitMQProducerService
|
||||
{
|
||||
private IModel channel;
|
||||
private IConnection connection;
|
||||
private readonly object connectionLock = new();
|
||||
private readonly ILogger<XRabbitMQProducerService> logger;
|
||||
private readonly XEventServiceConfiguration configuration;
|
||||
|
||||
public XRabbitMQProducerService(
|
||||
ILogger<XRabbitMQProducerService> logger,
|
||||
XEventServiceConfiguration configuration
|
||||
)
|
||||
) : base(configuration, logger)
|
||||
{
|
||||
//
|
||||
this.logger = logger;
|
||||
this.configuration = configuration;
|
||||
|
||||
//
|
||||
// Validate Configurations ...
|
||||
if (!configuration.IsValid() ||
|
||||
@@ -52,6 +46,9 @@ namespace xEventService.Providers
|
||||
/// <summary>
|
||||
/// Sending Message with Full Request Descriptor ...
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> SendMessageAsync(
|
||||
XEventRequest request,
|
||||
CancellationToken cancellationToken = default
|
||||
@@ -77,9 +74,41 @@ namespace xEventService.Providers
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sending a Message to Topic ...
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
/// <param name="topic"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> SendMessageAsync(
|
||||
XEventMessage message,
|
||||
string topic = XEventServiceConstants.XDefaultTopic,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await SendMessageAsync(
|
||||
request: new XEventRequest
|
||||
{
|
||||
Topic = topic,
|
||||
Message = message
|
||||
},
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sending a Message to Exchange ...
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
/// <param name="exchange"></param>
|
||||
/// <param name="routingKey"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> SendMessageAsync(
|
||||
XEventMessage message,
|
||||
string exchange = null,
|
||||
@@ -114,7 +143,7 @@ namespace xEventService.Providers
|
||||
{
|
||||
//
|
||||
// Ensure Connection is Alive ...
|
||||
await EnsureChannelAsync(cancellationToken);
|
||||
EnsureChannelAsync();
|
||||
|
||||
//
|
||||
// Serialize Message ...
|
||||
@@ -170,14 +199,22 @@ namespace xEventService.Providers
|
||||
try
|
||||
{
|
||||
//
|
||||
channel.Close();
|
||||
channel.Dispose();
|
||||
channel = null;
|
||||
if (channel != null)
|
||||
{
|
||||
//
|
||||
channel.Close();
|
||||
channel.Dispose();
|
||||
channel = null;
|
||||
}
|
||||
|
||||
//
|
||||
connection.Close();
|
||||
connection.Dispose();
|
||||
connection = null;
|
||||
if (connection != null)
|
||||
{
|
||||
//
|
||||
connection.Close();
|
||||
connection.Dispose();
|
||||
connection = null;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
@@ -228,29 +265,10 @@ namespace xEventService.Providers
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ensure Connection Established ...
|
||||
/// </summary>
|
||||
private async Task<bool> EnsureConnectionAsync()
|
||||
{
|
||||
//
|
||||
try
|
||||
{
|
||||
await EnsureChannelAsync();
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ensure Channel is Open and Exchange/Queue Declared ...
|
||||
/// </summary>
|
||||
private async Task EnsureChannelAsync(
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
private void EnsureChannelAsync()
|
||||
{
|
||||
//
|
||||
if (IsConnected())
|
||||
|
||||
Reference in New Issue
Block a user