Skip to content

Upgrade from 0.X to 1.0

Tatsuya Ono edited this page Feb 21, 2018 · 6 revisions

1.0 includes some backward incompatible changes.

Please don't rely on your test suites to judge if your application is ready for 1.X. The changes are mainly related to the error cases which your test suites might not have covered.

Read this document carefully and update your application code.

No more MatchError

Let's see AMQP.Queue.purge/2 as an example.

On 0.X:

  @spec purge(Channel.t, String.t) :: {:ok, map}
  def purge(%Channel{pid: pid}, queue) do
    queue_purge_ok(message_count: message_count) = :amqp_channel.call pid, queue_purge(queue: queue)
    {:ok, %{message_count: message_count}}
  end

This is how version 1.0 implements it:

  @spec purge(Channel.t, String.t) :: {:ok, map} | Basic.error
  def purge(%Channel{pid: pid}, queue) do
    case :amqp_channel.call(pid, queue_purge(queue: queue)) do
      queue_purge_ok(message_count: message_count) -> {:ok, %{message_count: message_count}}
      error -> {:error, error}
    end
  end

The difference is on the way they handle the error. When :amqp_channel.call returns error amqp 0.x would raise MatchError inside the call. However version 1.0 would handle the error and return {:error, :closing | :blocked} (AMQP.Basic.Error).

If your code is like below upgrading amqp to version 1.0 can fail silently:

AMQP.Channel.purge(channel, "myqueue")

You have to handle the error:

case AMQP.Channel.purge(channel, "myqueue") do
  {:ok, _} -> # action for success
  {:error, error} -> # action for failure
end

Or at least like this:

{:ok, _} = AMQP.Channel.purge(channel, "myqueue")

Then you would notice the error.

We have changed most APIs in such way on 1.0. Please check your code and change the calls by following the instruction above to support 1.0.

lager

AMQP 1.0 also upgrades rabbit_common and amqp_client from 3.6.x to 3.7.x. It adds some dependencies and lager is one of them.

To configure the logging, please read their document. You can use config.exs. See AMQP configuration and mix.exs as an example.

amqp_client

Please check the following pages for other update information.

Connection.open_direct/1 has been removed

Connection.open_redirect/1 has stopped working because of an issue on amqp_client. The API has been removed from amqp 1.0.0. We will be adding it again once it has been sorted on amqp_client. Check this issue for more detail: https://github.com/pma/amqp/issues/73