dashbitco / broadway_rabbitmq

A Broadway producer for RabbitMQ
193 stars 42 forks source link

econnrefused when deploying elixir project with broadway #105

Closed D4no0 closed 3 years ago

D4no0 commented 3 years ago

versions: elixir 1.12 OTP 24.0 broadway_rabbitmq :0.7 broadway: 1.0 amqp: 2.1.2

Suppose we have the following amqp configuration:

config :amqp,
  connections: [
    server: [
      url: "amqp://rabbitmq:rabbitmq@localhost"
    ]
  ],
  channels: [
    channel: [connection: :server]
  ]

With broadway producer configuration:

producer: [
        module: {
          BroadwayRabbitMQ.Producer,
          queue: "broadway_queue",
          qos: [prefetch_count: 50],
          declare: [durable: true],
          bindings: [{"outgoing-exchange", []}],
          on_failure: :reject
        },
        concurrency: 1
      ],

By default, when run with: iex -S mix, everything works as expected, no errors and side effects.

When creating a release however, after starting it, in log keeps appearing the error:

07:31:41.497 [error] Cannot connect to RabbitMQ broker: :econnrefused 07:31:57.607 [error] Cannot connect to RabbitMQ broker: :econnrefused 07:32:16.246 [error] Cannot connect to RabbitMQ broker: :econnrefused 07:32:38.095 [error] Cannot connect to RabbitMQ broker: :econnrefused 07:32:57.107 [error] Cannot connect to RabbitMQ broker: :econnrefused

I can confirm that there is a open connection, looking in rabbitmq management console.

When running a remote console with command:

> AMQP.Connection.open()
> {:error, :econnrefused}

However running:

AMQP.Connection.open("amqp://rabbitmq:rabbitmq@localhost")

Opens a connection successfully.

To my understanding this happens because broadway and amqp try to use the same connection. The thing that bothers me is that in development it works without any problems, even the connection to production rabbitmq server over tls.

Is this the case, or there is a bug?

josevalim commented 3 years ago

What happens if you specify your parameters directly in the Broadway connection?

        producer: [
          module:
            {BroadwayRabbitMQ.Producer,
            queue: "my_queue",
            connection: [
              username: "user",
              password: "password",
              host: "192.168.0.10"
            ],
D4no0 commented 3 years ago

It seems to work, and to confirm the theory, now when I run:

AMQP.Connection.open()

I get the error:

{:error, :econnrefused}

Broadway connects fine to the rabbitmq.

These interactions are quite weird, I think it should be documented about the default AMQP configuration interaction with broadway.

whatyouhide commented 3 years ago

Oh interesting 👀 I had no idea the amqp library has some kind of global configuration there? 🤔