我有两个实例RabbitMQ由IBM提供:
String uri1 = "amqps://admin:password@host1:31281/virtualhost";
String uri2 = "amqps://admin:password@host2:31281/virtualhost";
要连接RabbitMQ,有两个选项:
备选案文1:
ConnectionFactory factory = new ConnectionFactory();
factory.setUri(uri1);
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
备选案文2:
ConnectionFactory factory = new ConnectionFactory();
factory.setUsername("admin");
factory.setPassword("password");
factory.setHost("host1");
factory.setPort(31281);
factory.setVirtualHost("virtualhost");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
由于任何原因,我都不能用这个选项连接到rabbitmq。此选项将获得以下错误:
Exception in thread "main" java.util.concurrent.TimeoutException
at com.rabbitmq.utility.BlockingCell.get(BlockingCell.java:77)
at com.rabbitmq.utility.BlockingCell.uninterruptibleGet(BlockingCell.java:120)
at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:36)
at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:372)
at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:297)
at com.rabbitmq.client.impl.recovery.RecoveryAwareAMQConnectionFactory.newConnection(RecoveryAwareAMQConnectionFactory.java:62)
at com.rabbitmq.client.impl.recovery.AutorecoveringConnection.init(AutorecoveringConnection.java:99)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:900)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:859)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:817)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:954)
连接到集群rabbitmq的一种方法是:
List<AddressType> addressesList = ......;//Read from xml and load
Connection connection = factory.newConnection(addressesList);
但是我不知道如何用许多URI连接到一个集群rabbitmq,因为选项2不起作用。拜托,有什么建议吗?
发布于 2018-01-09 15:28:09
对不起,将rabbitmq与URI连接起来并不重要,问题是通过"List addressesList =.“连接;是因为兔子的这个组合实例使用SSL,而不考虑SSL,客户端java得到了以下错误:
Exception in thread "main" java.util.concurrent.TimeoutException
at com.rabbitmq.utility.BlockingCell.get(BlockingCell.java:77)
at com.rabbitmq.utility.BlockingCell.uninterruptibleGet(BlockingCell.java:120)
at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:36)
at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:372)
at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:297)
at com.rabbitmq.client.impl.recovery.RecoveryAwareAMQConnectionFactory.newConnection(RecoveryAwareAMQConnectionFactory.java:62)
at com.rabbitmq.client.impl.recovery.AutorecoveringConnection.init(AutorecoveringConnection.java:99)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:900)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:859)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:817)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:954)
然后我们可以使用信任库或简单地添加:
factory.useSslProtocol("TLSv1.2");
发布于 2018-01-06 15:40:54
让这个未经测试的代码试一试。我使用RabbitMQ Java客户端javadocs作为我的参考:
ConnectionFactory factory = new ConnectionFactory();
factory.setUsername("admin");
factory.setPassword("password");
factory.setVirtualHost("virtualhost");
Address address1 = new Address("host1", 31281);
Address a2 = new Address("host2", 31281);
List<Address> = new List<Address> { a1, a2 }; // I'm sure this is not the right syntax
AddressResolver addressResolver = factory.createAddressResolver(addresses);
Connection connection = factory.newConnection(addressResolver);
Channel channel = connection.createChannel();
https://stackoverflow.com/questions/48122685
复制相似问题