From effe2772ce5c1e2ba630c635af37a8e55b5b1a6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D1=82=D0=B0=D0=BD=D0=B8=D1=81=D0=BB=D0=B0=D0=B2=20?= =?UTF-8?q?=D0=A2=D0=B5=D1=80=D0=B5=D1=89=D0=B5=D0=BD=D0=BA=D0=BE=D0=B2?= Date: Tue, 26 Mar 2024 12:38:08 +0300 Subject: [PATCH 1/3] metricsFactory from DI --- .../ATI.Services.RabbitMQ.csproj | 2 +- ATI.Services.RabbitMQ/EventbusManager.cs | 23 ++++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/ATI.Services.RabbitMQ/ATI.Services.RabbitMQ.csproj b/ATI.Services.RabbitMQ/ATI.Services.RabbitMQ.csproj index f9bd10f..e86181c 100644 --- a/ATI.Services.RabbitMQ/ATI.Services.RabbitMQ.csproj +++ b/ATI.Services.RabbitMQ/ATI.Services.RabbitMQ.csproj @@ -16,7 +16,7 @@ 1701;1702;CS1591;CS1571;CS1573;CS1574 - + \ No newline at end of file diff --git a/ATI.Services.RabbitMQ/EventbusManager.cs b/ATI.Services.RabbitMQ/EventbusManager.cs index ba64208..69bde20 100644 --- a/ATI.Services.RabbitMQ/EventbusManager.cs +++ b/ATI.Services.RabbitMQ/EventbusManager.cs @@ -41,8 +41,8 @@ public class EventbusManager : IDisposable, IInitializer private readonly JsonSerializer _jsonSerializer; private readonly string _connectionString; - private readonly MetricsFactory _inMetricsFactory = MetricsFactory.CreateRabbitMqMetricsFactory(RabbitMetricsType.Subscribe, nameof(EventbusManager), additionalSummaryLabels: "rmq_app_id"); - private readonly MetricsFactory _outMetricsFactory = MetricsFactory.CreateRabbitMqMetricsFactory(RabbitMetricsType.Publish, nameof(EventbusManager)); + private readonly MetricsInstance _inMetrics; + private readonly MetricsInstance _outMetrics; private readonly ILogger _logger = LogManager.GetCurrentClassLogger(); private ConcurrentBag _subscriptions = new(); @@ -52,12 +52,19 @@ public class EventbusManager : IDisposable, IInitializer private static readonly UTF8Encoding BodyEncoding = new(false); private readonly RmqTopology _rmqTopology; - public EventbusManager(JsonSerializer jsonSerializer, IOptions options, RmqTopology rmqTopology) + public EventbusManager( + JsonSerializer jsonSerializer, + IOptions options, + RmqTopology rmqTopology, + MetricsFactory metricsFactory) { _options = options.Value; _connectionString = options.Value.ConnectionString; _jsonSerializer = jsonSerializer; _rmqTopology = rmqTopology; + + _inMetrics = metricsFactory.CreateRabbitMqMetricsFactory(RabbitMetricsType.Subscribe, nameof(EventbusManager), additionalSummaryLabels: "rmq_app_id"); + _outMetrics = metricsFactory.CreateRabbitMqMetricsFactory(RabbitMetricsType.Publish, nameof(EventbusManager)); _subscribePolicy = Policy.Handle() .WaitAndRetryForeverAsync(_ => _options.RabbitConnectInterval, @@ -113,7 +120,7 @@ public async Task PublishRawAsync( string.IsNullOrWhiteSpace(publishBody)) return; - using (_outMetricsFactory.CreateLoggingMetricsTimer(metricEntity, $"{exchangeName}:{routingKey}")) + using (_outMetrics.CreateLoggingMetricsTimer(metricEntity, $"{exchangeName}:{routingKey}")) { var messageProperties = GetProperties(additionalHeaders, withAcceptLang); var exchange = new Exchange(exchangeName); @@ -150,7 +157,7 @@ public async Task PublishAsync( publishObject == null) return; - using (_outMetricsFactory.CreateLoggingMetricsTimer(metricEntity, $"{exchangeName}:{routingKey}")) + using (_outMetrics.CreateLoggingMetricsTimer(metricEntity, $"{exchangeName}:{routingKey}")) { var messageProperties = GetProperties(additionalHeaders, withAcceptLang); var exchange = new Exchange(exchangeName); @@ -297,7 +304,7 @@ private async Task SubscribePrivateAsync( async Task HandleEventBusMessageWithPolicy(ReadOnlyMemory body, MessageProperties props, MessageReceivedInfo info) { - using (_inMetricsFactory.CreateLoggingMetricsTimer(metricEntity ?? "Eventbus", + using (_inMetrics.CreateLoggingMetricsTimer(metricEntity ?? "Eventbus", $"{info.Exchange}:{info.RoutingKey}", additionalLabels: props.AppId ?? "Unknown")) { @@ -329,7 +336,7 @@ private async Task BindConsumerAsync(QueueExchangeBinding mainQueueBinding, { return async (body, props, info) => { - using (_inMetricsFactory.CreateLoggingMetricsTimer(metricEntity ?? "Eventbus", + using (_inMetrics.CreateLoggingMetricsTimer(metricEntity ?? "Eventbus", $"{info.Exchange}:{info.RoutingKey}", additionalLabels: props.AppId ?? "Unknown")) { @@ -362,7 +369,7 @@ Func, MessageProperties, MessageReceivedInfo, Task> HandleP { return async (body, props, info) => { - using (_outMetricsFactory.CreateLoggingMetricsTimer($"{metricEntity ?? "Eventbus"}-Poison", $"{info.Exchange}:{info.RoutingKey}", + using (_outMetrics.CreateLoggingMetricsTimer($"{metricEntity ?? "Eventbus"}-Poison", $"{info.Exchange}:{info.RoutingKey}", additionalLabels: props.AppId ?? "Unknown")) { HandleMessageProps(props); From 6165e529fa55e1664f8b582c8857ac87b4382597 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D1=82=D0=B0=D0=BD=D0=B8=D1=81=D0=BB=D0=B0=D0=B2=20?= =?UTF-8?q?=D0=A2=D0=B5=D1=80=D0=B5=D1=89=D0=B5=D0=BD=D0=BA=D0=BE=D0=B2?= Date: Tue, 26 Mar 2024 13:22:33 +0300 Subject: [PATCH 2/3] update common lib --- ATI.Services.RabbitMQ/ATI.Services.RabbitMQ.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ATI.Services.RabbitMQ/ATI.Services.RabbitMQ.csproj b/ATI.Services.RabbitMQ/ATI.Services.RabbitMQ.csproj index e86181c..9601ffd 100644 --- a/ATI.Services.RabbitMQ/ATI.Services.RabbitMQ.csproj +++ b/ATI.Services.RabbitMQ/ATI.Services.RabbitMQ.csproj @@ -16,7 +16,7 @@ 1701;1702;CS1591;CS1571;CS1573;CS1574 - + \ No newline at end of file From 420b6cdf34bf1e89904893875a6be97506d3e6d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D1=82=D0=B0=D0=BD=D0=B8=D1=81=D0=BB=D0=B0=D0=B2=20?= =?UTF-8?q?=D0=A2=D0=B5=D1=80=D0=B5=D1=89=D0=B5=D0=BD=D0=BA=D0=BE=D0=B2?= Date: Thu, 28 Mar 2024 14:52:14 +0300 Subject: [PATCH 3/3] release version of atisu.services.common --- ATI.Services.RabbitMQ/ATI.Services.RabbitMQ.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ATI.Services.RabbitMQ/ATI.Services.RabbitMQ.csproj b/ATI.Services.RabbitMQ/ATI.Services.RabbitMQ.csproj index 9601ffd..e1cae18 100644 --- a/ATI.Services.RabbitMQ/ATI.Services.RabbitMQ.csproj +++ b/ATI.Services.RabbitMQ/ATI.Services.RabbitMQ.csproj @@ -16,7 +16,7 @@ 1701;1702;CS1591;CS1571;CS1573;CS1574 - + \ No newline at end of file