public ConnectionConfiguration Parse(string connectionString) { ConnectionString = connectionString; var connectionConfiguration = new ConnectionConfiguration(settings); var connectionConfigurationType = typeof(ConnectionConfiguration); foreach (var key in Keys.Cast <string>()) { var property = connectionConfigurationType.GetProperty(key, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance); property?.SetValue(connectionConfiguration, TypeDescriptor.GetConverter(property.PropertyType).ConvertFrom(this[key])); } if (connectionConfiguration.UseTls && !ContainsKey("port")) { connectionConfiguration.Port = 5671; } if (ContainsKey("host")) { ParseHosts(connectionConfiguration, this["host"] as string); } else { throw new Exception("Invalid connection string. 'host' value must be supplied. e.g: \"host=myServer\""); } if (ContainsKey("dequeuetimeout")) { var message = "The 'DequeueTimeout' connection string option has been removed. Consult the documentation for further information."; Logger.Error(message); throw new NotSupportedException(message); } if (ContainsKey("maxwaittimeforconfirms")) { var message = "The 'MaxWaitTimeForConfirms' connection string option has been removed. Consult the documentation for further information"; Logger.Error(message); throw new NotSupportedException(message); } if (ContainsKey("prefetchcount")) { var message = "The 'PrefetchCount' connection string option has been removed. Use 'EndpointConfiguration.UseTransport<RabbitMQTransport>().PrefetchCount' instead."; Logger.Error(message); throw new NotSupportedException(message); } if (ContainsKey("usepublisherconfirms")) { var message = "The 'UsePublisherConfirms' connection string option has been removed. Use 'EndpointConfiguration.UseTransport<RabbitMQTransport>().UsePublisherConfirms' instead."; Logger.Error(message); throw new NotSupportedException(message); } return(connectionConfiguration); }
public ConnectionFactory(string endpointName, ConnectionConfiguration connectionConfiguration, X509CertificateCollection clientCertificates, bool disableRemoteCertificateValidation, bool useExternalAuthMechanism) { if (endpointName is null) { throw new ArgumentNullException(nameof(endpointName)); } if (endpointName == string.Empty) { throw new ArgumentException("The endpoint name cannot be empty.", nameof(endpointName)); } this.endpointName = endpointName; if (connectionConfiguration == null) { throw new ArgumentNullException(nameof(connectionConfiguration)); } if (connectionConfiguration.Host == null) { throw new ArgumentException("The connectionConfiguration has a null Host.", nameof(connectionConfiguration)); } connectionFactory = new global::RabbitMQ.Client.ConnectionFactory { HostName = connectionConfiguration.Host, Port = connectionConfiguration.Port, VirtualHost = connectionConfiguration.VirtualHost, UserName = connectionConfiguration.UserName, Password = connectionConfiguration.Password, RequestedHeartbeat = connectionConfiguration.RequestedHeartbeat, NetworkRecoveryInterval = connectionConfiguration.RetryDelay, UseBackgroundThreadsForIO = true }; connectionFactory.Ssl.ServerName = connectionConfiguration.Host; connectionFactory.Ssl.Certs = clientCertificates; connectionFactory.Ssl.CertPath = connectionConfiguration.CertPath; connectionFactory.Ssl.CertPassphrase = connectionConfiguration.CertPassphrase; connectionFactory.Ssl.Version = SslProtocols.Tls12; connectionFactory.Ssl.Enabled = connectionConfiguration.UseTls; if (disableRemoteCertificateValidation) { connectionFactory.Ssl.AcceptablePolicyErrors = SslPolicyErrors.RemoteCertificateChainErrors | SslPolicyErrors.RemoteCertificateNameMismatch | SslPolicyErrors.RemoteCertificateNotAvailable; } if (useExternalAuthMechanism) { connectionFactory.AuthMechanisms = new[] { new ExternalMechanismFactory() }; } connectionFactory.ClientProperties.Clear(); foreach (var item in connectionConfiguration.ClientProperties) { connectionFactory.ClientProperties.Add(item.Key, item.Value); } }
public ConnectionFactory(string endpointName, ConnectionConfiguration connectionConfiguration, X509Certificate2Collection clientCertificateCollection, bool disableRemoteCertificateValidation, bool useExternalAuthMechanism, TimeSpan heartbeatInterval, TimeSpan networkRecoveryInterval, List <(string, int)> additionalHostnames)