ArieGato / serilog-sinks-rabbitmq

Serilog Sink for RabbitMq
Apache License 2.0
53 stars 51 forks source link

Unable to connect to RabbitMQ over SSL #98

Closed dmajcherlandstar closed 4 years ago

dmajcherlandstar commented 4 years ago

I'm trying to connect to RabbitMQ using SSL. The 5671 port is open on RabbitMQ and accepting connections, but when I try to connect to it through the sink, I get a "None of the specified endpoints were reachable" error in .NET and "handshake_timeout,handshake" error in the RabbitMQ log. Is there somewhere I need to tell the sink to initiate the handshake for SSL?

Here is my code:

        RabbitMQConfiguration config = new RabbitMQConfiguration
        {
          DeliveryMode = RabbitMQDeliveryMode.Durable,
          Hostname = "myhost.com",
          Port = 5671,
          Username = "username",
          Password = "password",
          VHost = "/",
          BatchPostingLimit = 100,
          Exchange = "local.engines.logs.exchange",
          ExchangeType = "direct"
        };

        LoggerConfiguration loggerConfiguration = new LoggerConfiguration()
           .Enrich.FromLogContext()
           .Enrich.WithExceptionDetails()
           .Enrich.WithMachineName()
           .Enrich.WithProperty("Application_Name", ConfigurationManager.AppSettings["ApplicationName"])
           .Enrich.WithProperty("Application_Version", Assembly.GetExecutingAssembly().GetName().Version);

        if (config != null)
          loggerConfiguration.WriteTo.RabbitMQ(config, new JsonFormatter());

        Log.Logger = loggerConfiguration.CreateLogger();

I'm using: .NET 4.7 RabbitMQ.Client 4.1.3 Serilog 2.8.0 Serilog.Sinks.RabbitMQ 2.0.2

madslyng commented 4 years ago

Hi @dmajcherlandstar

In v3.0.0 - so you need to upgrade to be able to have access to the SslOption. It's not sufficient to just change the port.

Your can find help on configuring the Sink correctly on RabbitMq.Clients website

Good luck.

dmajcherlandstar commented 4 years ago

steffenlyng, thanks for the response.

Ok, I upgraded to version 3.0.6 of Serilog.Sinks.RabbitMQ. I updated my code to the following, but I'm still not seeing messages in RabbitMQ. I turned off peer validation in RabbitMQ. Am I missing anything else?

Thanks

 RabbitMQClientConfiguration config = new RabbitMQClientConfiguration
        {
          DeliveryMode = RabbitMQDeliveryMode.Durable,
          Hostname = "myhost.com",
          Port = 5671,
          Username = "username",
          Password = "password",
          VHost = "/",
          BatchPostingLimit = 100,
          Exchange = "local.engines.logs.exchange",
          ExchangeType = "direct",
          SslOption = new SslOption() { ServerName = "myhost.com", Enabled = true, AcceptablePolicyErrors = SslPolicyErrors.RemoteCertificateNotAvailable | SslPolicyErrors.RemoteCertificateChainErrors | SslPolicyErrors.RemoteCertificateNameMismatch }
        };

        LoggerConfiguration loggerConfiguration = new LoggerConfiguration()
           .Enrich.FromLogContext()
           .Enrich.WithExceptionDetails()
           .Enrich.WithMachineName()
           .Enrich.WithProperty("Application_Name", ConfigurationManager.AppSettings["ApplicationName"])
           .Enrich.WithProperty("Application_Version", Assembly.GetExecutingAssembly().GetName().Version);

        if (config != null)
          loggerConfiguration.WriteTo.RabbitMQ(config, new JsonFormatter());

        Log.Logger = loggerConfiguration.CreateLogger();
dmajcherlandstar commented 4 years ago

I was able to get it working. I wasn't specifying the SslOption.Version property. Once I did that, it started working.

 RabbitMQClientConfiguration config = new RabbitMQClientConfiguration
        {
          DeliveryMode = RabbitMQDeliveryMode.Durable,
          Hostname = "myhost.com",
          Port = 5671,
          Username = "username",
          Password = "password",
          VHost = "/",
          BatchPostingLimit = 100,
          Exchange = "local.engines.logs.exchange",
          ExchangeType = "direct",
          SslOption = new SslOption() { ServerName = "myhost.com", Enabled = true, Version = SslProtocols.Tls12  }
        };

        LoggerConfiguration loggerConfiguration = new LoggerConfiguration()
           .Enrich.FromLogContext()
           .Enrich.WithExceptionDetails()
           .Enrich.WithMachineName()
           .Enrich.WithProperty("Application_Name", ConfigurationManager.AppSettings["ApplicationName"])
           .Enrich.WithProperty("Application_Version", Assembly.GetExecutingAssembly().GetName().Version);

        if (config != null)
          loggerConfiguration.WriteTo.RabbitMQ(config, new JsonFormatter());

        Log.Logger = loggerConfiguration.CreateLogger();