0

I'm running a stock RabbitMQ install on MacOS. Start the server up fine with just 'rabbitmq-server'.

Using the Java API I can easily connect to RabbitMQ with "localhost" as the host like this:

val factory = new ConnectionFactory()
factory.setHost( "localhost" )
val connection = factory.newConnection()

However, when I try a different IP (e.g. the actual IP of my machine) I get a connection refused error.

Exception in thread "main" java.net.ConnectException: Connection refused
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at com.rabbitmq.client.impl.FrameHandlerFactory.create(FrameHandlerFactory.java:32)
    at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:615)
    at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:639)
    at com.gwz.Junk$delayedInit$body.apply(Junk.scala:8)
    at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
    at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
    at scala.App$$anonfun$main$1.apply(App.scala:71)
    at scala.App$$anonfun$main$1.apply(App.scala:71)
    at scala.collection.immutable.List.foreach(List.scala:318)
    at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:32)
    at scala.App$class.main(App.scala:71)
    at com.gwz.Junk$.main(Junk.scala:5)
    at com.gwz.Junk.main(Junk.scala)

My ifconfig shows inet addresses like these:

inet 127.0.0.1 netmask 0xff000000
inet 172.16.240.21 netmask 0xffffff00 broadcast 172.16.240.255
inet 192.168.59.3 netmask 0xffffff00 broadcast 192.168.59.255
inet 10.0.0.125 netmask 0xffffff00 broadcast 10.0.0.255

The loopback 127.0.0.1 works. The others, however, don't. I need one of the other 3 to work.

Do I need to do something else to allow connection by my local IP?

Greg
  • 10,696
  • 22
  • 68
  • 98
  • It *might* help to explicitly state the port (i.e `localhost:5672`) – JCOC611 Jan 29 '15 at 22:30
  • Good thought. Just tried it and got an unknown host exception. It seems to be just expecting the host/IP not the port. (I think that's another setting.) – Greg Jan 29 '15 at 22:52
  • I think it should be `factory.setPort(5672)` then. – JCOC611 Jan 29 '15 at 22:54
  • I don't think its the port. Tried adding the above setPort and still connection refused. Using localhost or 127.0.0.1 with setPort as shown above did work, so unfortunately no change in behavior. Something's blocking the host. – Greg Jan 29 '15 at 23:07
  • More learnings... From a blurb in the docs, guest user (presumbably the default) can only connect to localhost--matches observed behavior. Docs say to allow guest to connect remotely use this as rabbitmq.config: [{rabbit, [{loopback_users, []}]}]. (with the period) Sound like just what I need--except it didn't work. Gave no errors but didn't allow remote connection. – Greg Jan 29 '15 at 23:21
  • Please read this post:http://stackoverflow.com/questions/22850546/cant-access-rabbitmq-web-management-interface-after-fresh-install/ – Gabriele Santomaggio Jan 30 '15 at 08:08

1 Answers1

1

There may be more than one solution, but what I found was this:

First open up loopback_users in rabbitmq.conf:

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

Then I put my local machine's IP address in rabbitmq-env.conf (wherever its installed on your machine):

NODE_IP_ADDRESS=10.0.1.45

This defaulted to localhost for me, so these two changes together allowed my guest account to be accessed with a non-localhost IP.

Greg
  • 10,696
  • 22
  • 68
  • 98
  • This is stated in our docs, the guest user can only connect via localhost: https://www.rabbitmq.com/access-control.html – old_sound Feb 02 '15 at 14:07