pma / amqp

Idiomatic Elixir client for RabbitMQ
MIT License
681 stars 124 forks source link

Connection error after updating to 1.3.0 #145

Closed williamweckl closed 5 years ago

williamweckl commented 5 years ago

After upgrading to 1.3.0 It does not connect to RabbitMQ anymore. After downgrading it to 1.2.2 it worked again.

Elixir version: 1.9.0 OTP: 22.0.3

My code that connects to AMQP:

def init(:ok) do
    rabbitmq_connect()
  end

  defp rabbitmq_connect do
    amqp_url = Application.get_env(:auth, :amqp_url)
    case Connection.open(amqp_url) do
      {:ok, conn} ->
        Logger.info "[Auth Event Message Broker] connected to RabbitMQ."
        # Get notifications when the connection goes down
        Process.monitor(conn.pid)
        # Everything else remains the same
        {:ok, chan} = Channel.open(conn)
        setup_exchange(chan)
        {:ok, %{channel: chan, connection: conn, exchange: @exchange}}
      {:error, error} ->
        # Reconnection loop
        Logger.error "[Auth Event Message Broker] connection error: #{error}"
        Logger.info "[Auth Event Message Broker] lost connect with RabbitMQ. Retrying..."
        :timer.sleep(10_000)
        rabbitmq_connect()
    end
  end

The logs:

12:55.436 [error] [Auth Event Message Broker] connection error: econnrefused
2019-09-04T01:12:55.436952+00:00 esm-api[esm-api-675d59c68d-87n7q]: web.1  | 01:12:55.436 [info] [Auth Event Message Broker] lost connect with RabbitMQ. Retrying...
ono commented 5 years ago

Hey @williamweckl. Thanks for reporting the issue. Can you share the amqp_url (without a credential and actual hostname of course) please?

Thanks!

nburkley commented 5 years ago

We also experienced the problem when upgrading to 1.3.0. Opening a connection returned a connection error.

Connection.open(config[:uri])
-> {:error, :econnrefused}

Haven't had a chance to debug it yet, we just reverted to 1.2.2

Our amqp_url is in the format amqp://username:password@hostname:port

ono commented 5 years ago

i will take a look at it this evening. thanks for reporting!

ono commented 5 years ago

@williamweckl @nburkley just released the bugfix with 1.3.1. let me know if you still see any issues. thanks again for reporting!

nburkley commented 5 years ago

great, thanks for the quick fix @ono!

williamweckl commented 5 years ago

Updated to 1.3.1 and problem still happen... econnrefused

nburkley commented 5 years ago

Upgrading to 1.3.1 fixed the problem for us.

@williamweckl, it might be helpful to include the amqp_url (without a credential and actual hostname).

williamweckl commented 5 years ago

@nburkley "amqp://user:password@xxxx.rmq.cloudamqp.com/xpto"

ono commented 5 years ago

@williamweckl i signed up cloudamqp.com and tried with URL. I successfully managed to open a connection with 1.3.1. Can you double check with your deps directory and make sure amqp has been updated?

williamweckl commented 5 years ago

It worked now after trying again and updating to 1.3.2. Don't know what I was doing wrong but sorry about the confusion.

Thanks!