public void Initialize() { var connectionConfiguration = ConnectionConfiguration.Create(connectionString, "ServiceControl.Monitoring"); connectionFactory = new ConnectionFactory(connectionConfiguration, null, false, false); }
public ConnectionFactory(string endpointName, ConnectionConfiguration connectionConfiguration, X509Certificate2Collection clientCertificateCollection, bool disableRemoteCertificateValidation, bool useExternalAuthMechanism, TimeSpan?heartbeatInterval, TimeSpan?networkRecoveryInterval) { 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 = heartbeatInterval ?? connectionConfiguration.RequestedHeartbeat, NetworkRecoveryInterval = networkRecoveryInterval ?? connectionConfiguration.RetryDelay, UseBackgroundThreadsForIO = true }; connectionFactory.Ssl.ServerName = connectionConfiguration.Host; connectionFactory.Ssl.Certs = clientCertificateCollection; 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); } }