using System; using System.Collections.Generic; // ReSharper disable UnusedMember.Global namespace Tapeti { /// /// Defines the connection parameters. /// public class TapetiConnectionParams { private IDictionary clientProperties; /// /// The hostname to connect to. Defaults to localhost. /// public string HostName { get; set; } = "localhost"; /// /// The port to connect to. Defaults to 5672. /// public int Port { get; set; } = 5672; /// /// The virtual host in RabbitMQ. Defaults to /. /// public string VirtualHost { get; set; } = "/"; /// /// The username to authenticate with. Defaults to guest. /// public string Username { get; set; } = "guest"; /// /// The password to authenticate with. Defaults to guest. /// public string Password { get; set; } = "guest"; /// /// The amount of message to prefetch. See http://www.rabbitmq.com/consumer-prefetch.html for more information. /// /// If set to 0, no limit will be applied. /// public ushort PrefetchCount { get; set; } = 50; /// /// The port the management plugin binds to. Only used when DeclareDurableQueues is enabled. Defaults to 15672. /// public int ManagementPort { get; set; } = 15672; /// /// Key-value pair of properties that are set on the connection. These will be visible in the RabbitMQ Management interface. /// Note that you can either set a new dictionary entirely, to allow for inline declaration, or use this property directly /// and use the auto-created dictionary. /// /// /// If any of the default keys used by the RabbitMQ Client library (product, version) are specified their value /// will be overwritten. See DefaultClientProperties in Connection.cs in the RabbitMQ .NET client source for the default values. /// public IDictionary ClientProperties { get => clientProperties ?? (clientProperties = new Dictionary()); set => clientProperties = value; } /// /// public TapetiConnectionParams() { } /// /// Construct a new TapetiConnectionParams instance based on standard URI syntax. /// /// new TapetiConnectionParams(new Uri("amqp://username:password@hostname/")) /// new TapetiConnectionParams(new Uri("amqp://username:password@hostname:5672/virtualHost")) /// public TapetiConnectionParams(Uri uri) { HostName = uri.Host; VirtualHost = string.IsNullOrEmpty(uri.AbsolutePath) ? "/" : uri.AbsolutePath; if (!uri.IsDefaultPort) Port = uri.Port; var userInfo = uri.UserInfo.Split(':'); if (userInfo.Length <= 0) return; Username = userInfo[0]; if (userInfo.Length > 1) Password = userInfo[1]; } } }