From 7def2cccd69c8c0b56b404dfa2a12d6827298953 Mon Sep 17 00:00:00 2001 From: Patryk Mamica Date: Wed, 16 Feb 2022 12:05:01 +0000 Subject: [PATCH 1/2] Hooking up AzureServiceBusProducerRegistryFactory to have configurable batch size --- .../AzureServiceBusProducerRegistryFactory.cs | 4 ++-- src/Paramore.Brighter/IAmAProducerRegistryFactory.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Paramore.Brighter.MessagingGateway.AzureServiceBus/AzureServiceBusProducerRegistryFactory.cs b/src/Paramore.Brighter.MessagingGateway.AzureServiceBus/AzureServiceBusProducerRegistryFactory.cs index a76a3731c3..17609541be 100644 --- a/src/Paramore.Brighter.MessagingGateway.AzureServiceBus/AzureServiceBusProducerRegistryFactory.cs +++ b/src/Paramore.Brighter.MessagingGateway.AzureServiceBus/AzureServiceBusProducerRegistryFactory.cs @@ -39,12 +39,12 @@ public AzureServiceBusProducerRegistryFactory( /// Creates message producers. /// /// A has of middleware clients by topic, for sending messages to the middleware - public IAmAProducerRegistry Create() + public IAmAProducerRegistry Create(int bulkSendBatchSize = 10) { var producers = new Dictionary(); foreach (var publication in _asbPublications) { - producers[publication.Topic] = AzureServiceBusMessageProducerFactory.Get(_clientProvider, publication);; + producers[publication.Topic] = AzureServiceBusMessageProducerFactory.Get(_clientProvider, publication, bulkSendBatchSize); } return new ProducerRegistry(producers); diff --git a/src/Paramore.Brighter/IAmAProducerRegistryFactory.cs b/src/Paramore.Brighter/IAmAProducerRegistryFactory.cs index a48739bb05..7c569b829a 100644 --- a/src/Paramore.Brighter/IAmAProducerRegistryFactory.cs +++ b/src/Paramore.Brighter/IAmAProducerRegistryFactory.cs @@ -1,4 +1,4 @@ -#region Licence +#region Licence /* The MIT License (MIT) Copyright © 2015 Toby Henderson @@ -35,7 +35,7 @@ public interface IAmAProducerRegistryFactory /// Creates message producers. /// /// A has of middleware clients by topic, for sending messages to the middleware - IAmAProducerRegistry Create(); + IAmAProducerRegistry Create(int bulkSendBatchSize = 10); } } From f077b96e4aaf2ec1df7e7b74fbde4f2d5dbb10cf Mon Sep 17 00:00:00 2001 From: Patryk Mamica Date: Wed, 16 Feb 2022 15:17:38 +0000 Subject: [PATCH 2/2] Relocating chunkSendSize away from producer create method --- .../AzureServiceBusProducerRegistryFactory.cs | 15 ++++++++++----- .../IAmAProducerRegistryFactory.cs | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Paramore.Brighter.MessagingGateway.AzureServiceBus/AzureServiceBusProducerRegistryFactory.cs b/src/Paramore.Brighter.MessagingGateway.AzureServiceBus/AzureServiceBusProducerRegistryFactory.cs index 17609541be..d3228f3aa1 100644 --- a/src/Paramore.Brighter.MessagingGateway.AzureServiceBus/AzureServiceBusProducerRegistryFactory.cs +++ b/src/Paramore.Brighter.MessagingGateway.AzureServiceBus/AzureServiceBusProducerRegistryFactory.cs @@ -7,11 +7,12 @@ public class AzureServiceBusProducerRegistryFactory : IAmAProducerRegistryFactor { private readonly IServiceBusClientProvider _clientProvider; private readonly IEnumerable _asbPublications; + private readonly int _bulkSendBatchSize; /// /// Creates a producer registry initialized with producers for ASB derived from the publications /// - /// The configuration of the connection to AWS + /// The configuration of the connection to ASB /// A set of publications - topics on the server - to configure public AzureServiceBusProducerRegistryFactory( AzureServiceBusConfiguration configuration, @@ -19,19 +20,23 @@ public AzureServiceBusProducerRegistryFactory( { _clientProvider = new ServiceBusConnectionStringClientProvider(configuration.ConnectionString); _asbPublications = asbPublications; + _bulkSendBatchSize = configuration.BulkSendBatchSize; } /// /// Creates a producer registry initialized with producers for ASB derived from the publications /// - /// The connection to AWS + /// The connection to ASB /// A set of publications - topics on the server - to configure + /// The maximum size to chunk messages when dispatching to ASB public AzureServiceBusProducerRegistryFactory( IServiceBusClientProvider clientProvider, - IEnumerable asbPublications) + IEnumerable asbPublications, + int bulkSendBatchSize = 10) { _clientProvider = clientProvider; _asbPublications = asbPublications; + _bulkSendBatchSize = bulkSendBatchSize; } @@ -39,12 +44,12 @@ public AzureServiceBusProducerRegistryFactory( /// Creates message producers. /// /// A has of middleware clients by topic, for sending messages to the middleware - public IAmAProducerRegistry Create(int bulkSendBatchSize = 10) + public IAmAProducerRegistry Create() { var producers = new Dictionary(); foreach (var publication in _asbPublications) { - producers[publication.Topic] = AzureServiceBusMessageProducerFactory.Get(_clientProvider, publication, bulkSendBatchSize); + producers[publication.Topic] = AzureServiceBusMessageProducerFactory.Get(_clientProvider, publication, _bulkSendBatchSize); } return new ProducerRegistry(producers); diff --git a/src/Paramore.Brighter/IAmAProducerRegistryFactory.cs b/src/Paramore.Brighter/IAmAProducerRegistryFactory.cs index 7c569b829a..a304074fb4 100644 --- a/src/Paramore.Brighter/IAmAProducerRegistryFactory.cs +++ b/src/Paramore.Brighter/IAmAProducerRegistryFactory.cs @@ -35,7 +35,7 @@ public interface IAmAProducerRegistryFactory /// Creates message producers. /// /// A has of middleware clients by topic, for sending messages to the middleware - IAmAProducerRegistry Create(int bulkSendBatchSize = 10); + IAmAProducerRegistry Create(); } }