antonyvorontsov / RabbitMQ.Client.Core.DependencyInjection

.Net Core library-wrapper of RabbitMQ.Client for Dependency Injection.
MIT License
111 stars 36 forks source link

Add SslOption feature for RabbitMQ connection configuration #9

Closed antonyvorontsov closed 4 years ago

antonyvorontsov commented 4 years ago

Add configurable SslOption for AmqpTcpEndpoint. Create own library model e.g. RabbitMq SslOption (so RabbitMQ.Client models will be still "hidden" by the library models). Such option will be available for manual configuration only.

antonyvorontsov commented 4 years ago

Sub-issue https://github.com/AntonyVorontsov/RabbitMQ.Client.Core.DependencyInjection/issues/9

skashif commented 4 years ago

Hi Antony,

I wanted to add SSL configuration to the connection factory, is there a way I can do this in the latest version of the library?

Best Regards.

antonyvorontsov commented 4 years ago

Hi Kashif!

No, there is no such functionality yet. But I wanted to add this ASAP. Right now I am working on adding structured docs to the project and after that I will try to implement the feature mentioned in this issue.

The main problem is that SSL options are hard to store in the appsettings.json files so I think the only way of making SSL connections possible in this library is making it manually configurable.

I think that appsettings.json will look the same as I mentioned in https://github.com/AntonyVorontsov/RabbitMQ.Client.Core.DependencyInjection/issues/5

{
 "RabbitMq": {
    "TcpEndpoints": [
      {
        "HostName": "hostname1",
        "Port": 5672
      },
      {
        "HostName": "hostname2",
        "Port": 45672
      },
      {
        "HostName": "hostname3",
        "Port": 345672
      }
    ],
    "Port": "5672",
    "UserName": "guest",
    "Password": "guest"
  }
}

And the Startup part will be like this

var clientOptions = new RabbitMqClientOptions();
Configuration.Bind("RabbitMq", clientOptions);
foreach(var endpoint in clientOptions.TcpEndpoints)
{
      // Configure SSL for each tcp endpoint as you wish.
      endpoint.Ssl = new SslOptionThatWillBeAdded();
}
services.AddRabbitMqClient(Configuration.GetSection(clientOptions));

The SSL option is the last feature of RabbitMQ.Client ConnectionFactory that I have not covered in this project yet. I will keep you updated on my progress.

Best Regards, Antony

antonyvorontsov commented 4 years ago

I have finally added an ssl option. There is a documentation section about such feature https://github.com/AntonyVorontsov/RabbitMQ.Client.Core.DependencyInjection/blob/master/docs/rabbit-configuration.md#ssl-configuration And there is an example how to use it https://github.com/AntonyVorontsov/RabbitMQ.Client.Core.DependencyInjection/tree/master/examples/Examples.SslProducer

This feature will be added in the next library release that I will drop off ASAP.