/// <summary> /// Configures the rabbit mq client connection for Sll properties. /// </summary> /// <param name="builder">Builder with appropriate properties set.</param> /// <returns>A connection factory builder</returns> /// <remarks> /// SSL configuration in Rabbit MQ is a complex topic. In order to ensure that rabbit can work without client presenting a client certificate /// and working just like an SSL enabled web-site which does not require certificate you need to have the following settings in your rabbitmq.config /// file. /// {ssl_options, [{cacertfile,"/path_to/cacert.pem"}, /// {certfile,"/path_to/server/cert.pem"}, /// {keyfile,"/path_to/server/key.pem"}, /// {verify,verify_none}, /// {fail_if_no_peer_cert,false}]} /// The last 2 lines are the important ones. /// </remarks> public IConnectionFactoryBuilder Configure(IConnectionFactoryBuilder builder) { builder.Add(connectionFactory => { connectionFactory.Ssl.Enabled = true; if (!_clientCertificateRequired) { // These properties need to be set as empty for the Rabbit MQ client. Null's cause an exception in the client library. connectionFactory.Ssl.CertPath = string.Empty; connectionFactory.Ssl.CertPassphrase = string.Empty; connectionFactory.Ssl.ServerName = string.Empty; // Because no client certificate is present we must allow the remote certificate name mismatch for the connection to succeed. _acceptablePolicyErrors = _acceptablePolicyErrors | SslPolicyErrors.RemoteCertificateNameMismatch; } else { connectionFactory.Ssl.CertPath = _certificatePath; connectionFactory.Ssl.CertPassphrase = _passphrase; connectionFactory.Ssl.ServerName = _serverName; } connectionFactory.Ssl.AcceptablePolicyErrors = _acceptablePolicyErrors; connectionFactory.Ssl.Version = SslProtocols.Tls; return(connectionFactory); }); return(builder); }
public ITransportFactoryBuilder Configure(ITransportFactoryBuilder builder) { IConnectionFactoryBuilder connectionFactoryBuilder = CreateBuilder(); builder.AddConnectionFactoryBuilder(_address.Uri, connectionFactoryBuilder); return(builder); }
IConnectionHandler <TransportConnection> GetConnection( Cache <ConnectionFactory, IConnectionHandler <TransportConnection> > cache, IRabbitEndpointAddress address) { ConnectionFactory factory = SanitizeConnectionFactory(address); return(cache.Get(factory, _ => { if (_log.IsDebugEnabled) { _log.DebugFormat("Creating RabbitMQ connection: {0}", address.Uri); } IConnectionFactoryBuilder builder = _connectionFactoryBuilders.Get(factory, __ => { if (_log.IsDebugEnabled) { _log.DebugFormat("Using default configurator for connection: {0}", address.Uri); } var configurator = new ConnectionFactoryConfigurator(address); return configurator.CreateBuilder(); }); ConnectionFactory connectionFactory = builder.Build(); if (_log.IsDebugEnabled) { _log.DebugFormat("RabbitMQ connection created: {0}:{1}/{2}", connectionFactory.HostName, connectionFactory.Port, connectionFactory.VirtualHost); } var connection = new TransportConnection(connectionFactory); var connectionHandler = new ConnectionHandler <TransportConnection>(connection); return connectionHandler; })); }
public void AddConnectionFactoryBuilder(Uri uri, IConnectionFactoryBuilder connectionFactoryBuilder) { _connectionFactoryBuilders[uri] = connectionFactoryBuilder; }
public IConnectionFactoryBuilder Configure(IConnectionFactoryBuilder builder) { builder.Add(Configure); return(builder); }