From 22deb86b0819d39fc7bcdae97a67a2e57b137b9e Mon Sep 17 00:00:00 2001 From: Peter Hunt Date: Mon, 6 Sep 2021 09:14:23 +0100 Subject: [PATCH 1/2] Allow setting of individual properties from Uri in ConnectionFactory --- .../Options/FactoryOptions.cs | 28 ++++++++++++++++++- .../Pools/ConnectionPool.cs | 17 ++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/HouseofCat.RabbitMQ/Options/FactoryOptions.cs b/src/HouseofCat.RabbitMQ/Options/FactoryOptions.cs index 7174671b..7c7b9886 100644 --- a/src/HouseofCat.RabbitMQ/Options/FactoryOptions.cs +++ b/src/HouseofCat.RabbitMQ/Options/FactoryOptions.cs @@ -1,15 +1,41 @@ using System; +using RabbitMQ.Client; namespace HouseofCat.RabbitMQ { public class FactoryOptions { /// - /// ConnectionFactory (RabbitMQ) Uri connection string. + /// ConnectionFactory (RabbitMQ) Uri connection string. Set to null to use individual properties. /// amqp(s)://guest:guest@localhost:5672/vhost /// public Uri Uri { get; set; } = new Uri("amqp://guest:guest@localhost:5672/"); + /// + /// ConnectionFactory (RabbitMQ) virtual host property. Use in lieu of Uri connection string. + /// + public string VirtualHost { get; set; } = ""; + + /// + /// ConnectionFactory (RabbitMQ) username property. Use in lieu of Uri connection string. + /// + public string UserName { get; set; } = "guest"; + + /// + /// ConnectionFactory (RabbitMQ) password property. Use in lieu of Uri connection string. + /// + public string Password { get; set; } = "guest"; + + /// + /// ConnectionFactory (RabbitMQ) host name property. Use in lieu of Uri connection string. + /// + public string HostName { get; set; } = "localhost"; + + /// + /// ConnectionFactory (RabbitMQ) port property. Use in lieu of Uri connection string. + /// + public int Port { get; set; } = AmqpTcpEndpoint.UseDefaultPort; + /// /// ConnectionFactory (RabbitMQ) max connection property. /// diff --git a/src/HouseofCat.RabbitMQ/Pools/ConnectionPool.cs b/src/HouseofCat.RabbitMQ/Pools/ConnectionPool.cs index d96dcccd..73b38c15 100644 --- a/src/HouseofCat.RabbitMQ/Pools/ConnectionPool.cs +++ b/src/HouseofCat.RabbitMQ/Pools/ConnectionPool.cs @@ -50,7 +50,6 @@ private ConnectionFactory CreateConnectionFactory() { var cf = new ConnectionFactory { - Uri = Options.FactoryOptions.Uri, AutomaticRecoveryEnabled = true, TopologyRecoveryEnabled = Options.FactoryOptions.TopologyRecovery, NetworkRecoveryInterval = TimeSpan.FromSeconds(Options.FactoryOptions.NetRecoveryTimeout), @@ -60,6 +59,22 @@ private ConnectionFactory CreateConnectionFactory() DispatchConsumersAsync = Options.FactoryOptions.EnableDispatchConsumersAsync, }; + if (Options.FactoryOptions.Uri != null) + { + cf.Uri = Options.FactoryOptions.Uri; + } + else + { + cf.VirtualHost = Options.FactoryOptions.VirtualHost; + cf.HostName = Options.FactoryOptions.HostName; + cf.UserName = Options.FactoryOptions.UserName; + cf.Password = Options.FactoryOptions.Password; + if (Options.FactoryOptions.Port != AmqpTcpEndpoint.UseDefaultPort) + { + cf.Port = Options.FactoryOptions.Port; + } + } + if (Options.FactoryOptions.SslOptions.EnableSsl) { cf.Ssl = new SslOption From f9b2a7ae1ea8441078f0c912f0c1b8c16001e9b9 Mon Sep 17 00:00:00 2001 From: Peter Hunt Date: Mon, 6 Sep 2021 09:16:48 +0100 Subject: [PATCH 2/2] Update version.props again --- version.props | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/version.props b/version.props index 2eb1584e..df6164c4 100644 --- a/version.props +++ b/version.props @@ -1,7 +1,7 @@ - 1.2.1 - 1.2.1 - 1.2.1 + 1.2.2 + 1.2.2 + 1.2.2