Exemplo n.º 1
0
        public ConnectionFactory(ConnectionConfiguration connectionConfiguration, X509CertificateCollection clientCertificates, bool disableRemoteCertificateValidation, bool useExternalAuthMechanism)
        {
            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,
                AutomaticRecoveryEnabled  = true,
                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);
            }
        }
Exemplo n.º 2
0
        public ConnectionFactory(ConnectionConfiguration connectionConfiguration, X509CertificateCollection clientCertificates)
        {
            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,
                AutomaticRecoveryEnabled  = true,
                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;

            connectionFactory.ClientProperties.Clear();

            foreach (var item in connectionConfiguration.ClientProperties)
            {
                connectionFactory.ClientProperties.Add(item.Key, item.Value);
            }
        }