RabbitMQServer Connection String with SSL Option

Is there is an example of using ServiceStack with RabbitMQ to establish a secure SSL/TLS 1.2 connection to the RabbitMQ Server? I’ve tried a few connection combinations without any luck. I’m not try to validate the server or pass the client certificate to the server.

Not that I’m aware of, this is the RabbitMQ docs they have on connecting to RabbitMQ in .NET with SSL which suggests you need to populate a ConnectionFactory with SSL Config which you can pass in, ServiceStack’s RabbitMQ with:

var cf = new ConnectionFactory();
//configure with SSL

var mqServer = new RabbitMqServer(new RabbitMqMessageFactory(cf));

Ya, here’s what I’m trying. I can connect (w/o SSL) when running my MQServer Client and Service on the localhost with RabbitMQ. Essentially my development environment. If I publish to a standalone server that has access to a standalone RabbitMQ server I get "None of the specified endpoints were reachable. (*Note - It connects and runs fine if I pass in the Connection, RabbitMQUser, and RabbitMQPass to the RabbitMQServer constructor) So I know it should be able to connect it just doesn’t when using the ConnectionFactory. Maybe you will notice something in my logic below.

[Inside a Plugin]

var factory = new ConnectionFactory();
factory.HostName = _rabbitMQHost;
factory.Port = _rabbitMQPort;
RabbitMqMessageFactory msgFactory = new RabbitMqMessageFactory(factory);  
container.Register<IMessageService>(c => new RabbitMqServer(msgFactory)
{
    ErrorHandler = MQServerError,
    RetryCount = 0,
});

[AppHost - OnAfterInit]
var mqServer = container.Resolve<IMessageService>();

mqServer.RegisterHandler....
...

mqServer.Start();  //Throws no endpoints are reachable

Update…

I used the Connection Factory with the following code with success. Had Self-Signed certificate that also caused some special handling in the Certificate Validation Callback.

var factory = new ConnectionFactory();
factory.HostName        =  [Host Name Here];
factory.Ssl.Enabled     = true;
factory.Ssl.ServerName = [Host Name Here];
factory.Ssl.Version = System.Security.Authentication.SslProtocols.Tls12;

factory.Ssl.CertificateValidationCallback = [Certificate Validation Callback Method];
factory.Port = [Port for SSL];
factory.UserName        = [UserName];
factory.Password        = [Password];
RabbitMqMessageFactory msgFactory = new RabbitMqMessageFactory(factory);
container.Register<IMessageService>(c => new RabbitMqServer(msgFactory)
{
    ErrorHandler = [Error Callback Method];
    RetryCount = 0
});

RabbitMqServer mqServer = (RabbitMqServer)container.Resolve<IMessageService>();

mqServer.DisablePriorityQueues = true;
mqServer.AutoReconnect = true;

mqServer.RegisterHandler<...>
mqServer.Start();
1 Like