-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
When using dotnetcore/CAP with a RabbitMQ cluster that has SSL enabled, the connection cannot be established.
After investigating the source code, it seems that when multiple hosts are configured (comma-separated), the generated Endpoint objects are created without assigning the corresponding SSL configuration. As a result:
The default port and protocol are used instead of the SSL configuration.
Connections fail because the client attempts a non-SSL connection to an SSL-enabled cluster.

Error message
DotNetCore.CAP.Internal.ConsumerRegister[0] Broker Unreachable DotNetCore.CAP.BrokerConnectionException: Broker Unreachable ---> RabbitMQ.Client.Exceptions.BrokerUnreachableException: None of the specified endpoints were reachable ---> System.AggregateException: One or more errors occurred. (Connection failed, host 192.168.2.17:5672) (Connection failed, host 192.168.2.22:5672) (Connection failed, host 192.168.2.19:5672) ---> RabbitMQ.Client.Exceptions.ConnectFailureException: Connection failed, host 192.168.2.17:5672
Root cause:
`
if (options.HostName.Contains(","))
{
options.ConnectionFactoryOptions?.Invoke(factory);
return () => factory.CreateConnectionAsync(AmqpTcpEndpoint.ParseMultiple(options.HostName));
}
`
The AmqpTcpEndpoint.ParseMultiple(options.HostName) method generates Endpoint objects without applying the SslOptions configuration, which leads to incorrect connections.
When creating endpoints from multiple hosts, explicitly apply the SslOptions configuration from the factory. For example:
`
if (options.HostName.Contains(","))
{
options.ConnectionFactoryOptions?.Invoke(factory);
var endpoints = AmqpTcpEndpoint.ParseMultiple(options.HostName);
foreach (var endpoint in endpoints)
{
// Ensure SSL options are applied
endpoint.Ssl = factory.Ssl;
}
return () => factory.CreateConnectionAsync(endpoints);
}
`