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