0
votes

I've been running into an issue lately. I'm trying to send packets to a remote server using RabbitMQ and Java for quite some time and I really need some help. Here is what my code looks like

ConnectionFactory factory = new ConnectionFactory();
//factory.setHost("localhost");
factory.setUsername("dev");
factory.setPassword("/*user password*/");
factory.setVirtualHost("/"); //not really sure what this means
factory.setHost("/*remote server IP*/"); //is this correct
factory.setPort(5672);
connection = factory.newConnection();

I am using Windows Server 2012, I've added rules to the firewall to allow both UDP & TCP on ports 5672 and 15672 for inbound connections. Would these also be the ports for outgoing? I assume I'd have to allow on these ports on my desktop as well. I know my packets send and work locally, tested that plenty of times. I just can't get that remote connection to work without timing out. I'd love help!

1
You need only tcp 5672 . The port 15672 is for management port. And what exactly your problem ? Have you tried to open also outgoing ? Because you need it - Gabriele Santomaggio
Hi Gabriele, thanks for the response. All I'm trying to do is send packets from my desktop to a remote server. I get a connection timeout each time. I have my RabbitMQ instance running on the server and nothing is getting there. I'm trying to use AMQP to accomplish this if that helps. I just checked that all the ports were open and I get nothing still. I also set up another user account for connecting. - snurby77
It is usually a firewall problem, try using telnet youserver 5672 and see if it works - Gabriele Santomaggio
You're a god send Gabriele! Turns out when you do windows inbound rules you have to set remote port to any. Telnet worked out perfectly!! Now just to fix some of the fun crashes while getting the messages ;) Thanks Gabriele! - snurby77

1 Answers

1
votes

I think you are right to create this connection but did you configure your broker sever (Rabbitmq)?

If not, at the beginning, the default user name of broker server is guest and password is guest.

But problem is, the guest user is prohibited from connecting to the broker remotely. it can only connect over a localhost.

Please configure your server by adding new:

  • user
  • password
  • vhost[Virtual hosts provide logical grouping and separation of resources].

or

To allow the guest user to connect from a remote host, you should set the loopback_users configuration item to []. A complete config code look like:

[{rabbit, [{loopback_users, []}]}].

For sake of better understand and clarify those question's answer, I explained briefly.

  • userName : your Rabbitmq server login user name
  • password : login password
  • virtualHost : your created virtualHost name. Default vhost is "/"
  • hostName : your host server name(where rabbitmq broker is located) or IP address.
  • hostPortNumber : your host server port number

You can alternatively use URIs to create connection:

ConnectionFactory factory = new ConnectionFactory();
factory.
setUri("amqp://userName:password@hostName:portNumber/virtualHost");
Connection conn = factory.newConnection();

I hope it will be worked fine. If you have any query against this answer, pleas let me comments bellow.