我正在使用 Python3.6 连接到 RabbitMQ。此连接使用 TLSv1.2 协议。设置 SSL 的连接参数:
cxt = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
ssl_options = pika.SSLOptions(context=cxt, server_hostname=rabbit_config['HOST'])
conn_params = pika.ConnectionParameters(port=rabbit_config['PORT'],
ssl_options=ssl_options,
credentials=creds,
virtual_host=rabbit_config['VIRTUAL_HOST'],
channel_max=channel_size,
heartbeat=heart_beat)
连接到 rabbitMq 时出现以下错误:
AMQPConnectionError: (AMQPConnectorSocketConnectError: ConnectionRefusedError(61, 'Connection refused'),)
我已经为Connection Parameters和TLS params example推荐了 pika 文档,但到目前为止还没有成功。
连接到同一个 Rabbit 主机的类似代码在 Java 中工作:
@Bean
CachingConnectionFactory connectionFactory(String host,
Integer port, String username,
String password, boolean ssl,
String sslAlgorithm) throws KeyManagementException, NoSuchAlgorithmException {
ConnectionFactory connectionFactory = new ConnectionFactory();
connectionFactory.setHost(host);
connectionFactory.setPort(port);
connectionFactory.setUsername(username);
connectionFactory.setPassword(password);
if (ssl) {
connectionFactory.useSslProtocol();
connectionFactory.useSslProtocol(sslAlgorithm);
}
CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(connectionFactory);
cachingConnectionFactory.setRequestedHeartBeat(50);
cachingConnectionFactory.setChannelCacheSize(10);
return cachingConnectionFactory;
}