Complete xEventService ...

This commit is contained in:
2026-08-19 22:44:39 +03:30
parent e05420b1aa
commit 079048dff5
8 changed files with 389 additions and 27 deletions
+23 -10
View File
@@ -51,7 +51,7 @@ namespace xEventService.Providers
//
SetupConnection();
DeclareTopology();
DeclareTopology(topic);
consumer = new AsyncEventingBasicConsumer(channel);
}
@@ -68,6 +68,7 @@ namespace xEventService.Providers
// For Fix Blocking Synchronous ...
await Task.Yield();
using var cts = new CancellationTokenSource();
logger.LogInformation($"RabbitMQ Cosume Topic: {topic} ...");
//
// Subscribe to Topic ...
@@ -103,9 +104,10 @@ namespace xEventService.Providers
);
}
}
catch
catch (Exception ex)
{
//
logger.LogError($"RabbitMQ Cosume Error: {ex.Message} ...");
if (configuration.RabbitMQ.ManualAck)
{
//
@@ -153,10 +155,20 @@ namespace xEventService.Providers
public override async Task StopAsync(CancellationToken cancellationToken)
{
//
channel.Close();
channel.Dispose();
connection.Close();
connection.Dispose();
if (channel != null)
{
//
channel.Close();
channel.Dispose();
}
//
if (connection != null)
{
//
connection.Close();
connection.Dispose();
}
//
await base.StopAsync(cancellationToken);
@@ -199,8 +211,9 @@ namespace xEventService.Providers
if (result.IsNullOrEmpty())
{
//
var exchangeName = topic ?? configuration.RabbitMQ.Exchange;
var digits = Guid.NewGuid().ToString().GetDigits();
result = $"{configuration.RabbitMQ.Exchange}[{digits}]";
result = $"{exchangeName}[{digits}]";
}
//
@@ -228,12 +241,12 @@ namespace xEventService.Providers
channel = connection.CreateModel();
}
private void DeclareTopology()
private void DeclareTopology(string topic)
{
//
channel.ExchangeDeclare(
arguments: null,
exchange: configuration.RabbitMQ.Exchange,
exchange: topic ?? configuration.RabbitMQ.Exchange,
durable: configuration.RabbitMQ.ExchangeDurable,
autoDelete: configuration.RabbitMQ.ExchangeAutoDelete,
type: configuration.RabbitMQ.ExchangeType.GetStringValue()
@@ -255,7 +268,7 @@ namespace xEventService.Providers
channel.QueueBind(
arguments: null,
queue: queueName,
exchange: configuration.RabbitMQ.Exchange,
exchange: topic ?? configuration.RabbitMQ.Exchange,
routingKey: configuration.RabbitMQ.RoutingKey
);
}