Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error message shows different ports #137

Open
0x5d opened this issue Apr 2, 2018 · 1 comment
Open

Error message shows different ports #137

0x5d opened this issue Apr 2, 2018 · 1 comment

Comments

@0x5d
Copy link
Contributor

0x5d commented Apr 2, 2018

Hi!
I'm getting this error while running my service, which uses op-rabbit:

[error] c.n.a.r.ConnectionActor - akka://application/user/rabbit/connection in Disconnected received Connect: can't connect to amqp:/myuser@{myhost:5671}:5672//, retrying in 10 seconds

and other times, when I run it, the ports are swapped:

[error] c.n.a.r.ConnectionActor - akka://application/user/rabbit/connection in Disconnected received Connect: can't connect to amqp://myuser@{myhost:5672}:5671//, retrying in 10 seconds

(Using myuser and myhost as placeholders)

This is my config:

op-rabbit {
  topic-exchange-name = "myexchange"
  channel-dispatcher = "op-rabbit.default-channel-dispatcher"
  default-channel-dispatcher {
    type = Dispatcher
    executor = "fork-join-executor"
    fork-join-executor {
      parallelism-min = 2
      parallelism-factor = 2.0
      parallelism-max = 4
    }
    throughput = 100
  }
  connection {
    virtual-host = "/"
    hosts = [${?RABBIT_HOST}]
    port = ${?RABBIT_PORT}
    username = ${?RABBIT_USERNAME}
    password = ${?RABBIT_PASSWORD}
    ssl = false
    connection-timeout = 3s
  }
}

These are the env vars I'm running it with:

export RABBIT_HOST=myhost RABBIT_PORT=5671 RABBIT_USERNAME=myuser RABBIT_PASSWORD=mypassword

What caught my eye was the 2 different ports in the error message, 5671 and 5672. How do I know which port is being used?

@timcharper
Copy link
Member

That is strange indeed. I might double check how things are getting configured.

The URL that you see in the error message is being rendered via this code:

https://github.com/NewMotion/akka-rabbitmq/blob/caa40268a80150865b7e813c5d32fd52c9c8685b/src/main/scala/akka/rabbitmq/package.scala#L23

  implicit class RichConnectionFactory(val self: ConnectionFactory) extends AnyVal {
    def uri: String = "amqp://%s@%s:%d/%s".format(self.getUsername, self.getHost, self.getPort, self.getVirtualHost)
  }

The curly braces come from the following code:

https://github.com/SpinGo/op-rabbit/blob/master/core/src/main/scala/com/spingo/op_rabbit/ClusterConnectionFactory.scala#L16

  override def getHost = {
    if (hosts.nonEmpty)
      s"{${hosts.mkString(",")}}"
    else
      super.getHost
  }

We don't even call setPort on the connectionFactory anywhere in the op-rabbit code. The port used is the one in curly braces. This is an area of the library that should be cleaned up. It's a side effect of an oddness with the upstream RabbitMQ Java library; there's not a mechanism to pass multiple ports in to connectionFactory as it was relatively retrofitted in.

Interesting to note, 5672 is the default port. 5671 is the SSL port. So, the value of the port you are seeing outside of the curly braces is being determined by this method: https://github.com/rabbitmq/rabbitmq-java-client/blob/master/src/main/java/com/rabbitmq/client/ConnectionFactory.java#L187

The port value for inside of the curly braces is determined here:

https://github.com/SpinGo/op-rabbit/blob/master/core/src/main/scala/com/spingo/op_rabbit/ConnectionParams.scala#L79

So, the only reason I can think of for the nondeterminism is perhaps you have a nondeterministic load order for your config. Sometimes, reference.conf is probably superseding application.conf, and other times, vice versa.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants