简体   繁体   中英

Rabbitmq Server : how to set up many ports for Amqp service

I want to set up two rabbitmq servers in two machines, these two servers will communicate in two differents ports. These two machines that i'm using are pingable and they have the same Rabbitmq Username/password. According to RabbitMQ documentation, For any servers that want to use the message queue, only 5672 is required. when I try to connect with another port, let's say for example 567, I get this error :

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)

here's the code that i'm using :

    connectionFactory = new ConnectionFactory();
    connectionFactory.setUsername("guest");
    connectionFactory.setPassword("guest");
    connectionFactory.setHost("localhost");
    connectionFactory.setPort(5672);

First of all, to use 567 port, or any port with a number smaller than 1024 is not such a good idea. Of course if the port is free on your machine you may use it, but it's simply cleaner to pick one bigger than 1024. Here is the list of well known ports.
For the second part, the port has to be registered to rabbitmq in it's config. Everything is well explained in the docs , just look for tcp_listeners . I will just quote one part:

[ {rabbit, [{tcp_listeners, [5673]}]} ].
This example will alter the port RabbitMQ listens on for AMQP 0-9-1 client connections from 5672 to 5673.

This code did the trick [ { rabbit, [ {tcp_listeners, [5673,5672]}, %% {tcp_listeners, [{"127.0.0.1", 5672}, %% {"127.0.0.1", 5673}]},
{loopback_users, []} ] } ].

Thank's for your help !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM