我想在兩臺機器上設置兩個rabbitmq服務器,這兩個服務器將在兩個不同的端口進行通信。我使用的這兩臺機器是可ping通的,並且它們具有相同的Rabbitmq用戶名/密碼。根據RabbitMQ文檔,對於任何想要使用消息隊列的服務器,只需要5672。 當我嘗試用另一個端口進行連接,讓我們說,例如567,我得到這個錯誤:Rabbitmq服務器:如何爲Amqp服務設置多個端口
Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at com.rabbitmq.client.impl.FrameHandlerFactory.create(FrameHandlerFactory.java:32)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:676)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:722)
at rmqServer.ServerSimple.init(ServerSimple.java:75)
at rmqServer.ServerSimple.main(ServerSimple.java:132)
Exception in thread "main" java.lang.NullPointerException
at rmqServer.ServerSimple.activateConsumer(ServerSimple.java:97)
at rmqServer.ServerSimple.main(ServerSimple.java:133)
下面是我使用的代碼:
connectionFactory = new ConnectionFactory();
connectionFactory.setUsername("guest");
connectionFactory.setPassword("guest");
connectionFactory.setHost("localhost");
connectionFactory.setPort(5672);