Skip to content
Advertisement

How to setup Elixir project to use RabbitMQ via amqp?

I want to use rabbitMQ from my elixir phoenix app via amqp. I followed tutorial on official website but still during mix.deps compile, I get an error:

include/amqp_gen_consumer_spec.hrl:30: syntax error before: '/'
include/amqp_gen_consumer_spec.hrl:31: syntax error before: '/'
include/amqp_gen_consumer_spec.hrl:32: syntax error before: '/'
include/amqp_gen_consumer_spec.hrl:34: syntax error before: '/'
include/amqp_gen_consumer_spec.hrl:35: syntax error before: '/'
include/amqp_gen_consumer_spec.hrl:36: syntax error before: '/'
include/amqp_gen_consumer_spec.hrl:37: syntax error before: '/'
include/amqp_gen_consumer_spec.hrl:38: syntax error before: '/'
include/amqp_gen_consumer_spec.hrl:39: syntax error before: '/'
include/amqp_gen_consumer_spec.hrl:42: syntax error before: '/'
include/amqp_gen_consumer_spec.hrl:30: syntax error before: '/'
include/amqp_gen_consumer_spec.hrl:31: syntax error before: '/'
include/amqp_gen_consumer_spec.hrl:32: syntax error before: '/'
include/amqp_gen_consumer_spec.hrl:34: syntax error before: '/'
include/amqp_gen_consumer_spec.hrl:35: syntax error before: '/'
include/amqp_gen_consumer_spec.hrl:36: syntax error before: '/'
include/amqp_gen_consumer_spec.hrl:37: syntax error before: '/'
include/amqp_gen_consumer_spec.hrl:38: syntax error before: '/'
include/amqp_gen_consumer_spec.hrl:39: syntax error before: '/'
include/amqp_gen_consumer_spec.hrl:42: syntax error before: '/'
Compiling src/amqp_selective_consumer.erl failed:
ERROR: compile failed while processing /home/bmarkons/soc2016-marko/telegram/deps/amqp_client: rebar_abort
** (Mix) Could not compile dependency :amqp_client, "/usr/bin/rebar compile skip_deps=true deps_dir="/home/bmarkons/soc2016-marko/telegram/_build/dev/lib"" command failed. You can recompile this dependency with "mix deps.compile amqp_client", update it with "mix deps.update amqp_client" or clean it with "mix deps.clean amqp_client"

Terminal screenshot

I added only :amqp and {:amqp, “~> 0.1.4”}, in mix.exs file:

def application do
    [mod: {App, []},
     applications: [:phoenix, :phoenix_pubsub, :phoenix_html, :cowboy, :logger, :gettext,
                    :phoenix_ecto, :postgrex, :amqp]]
end

defp deps do
    [{:phoenix, "~> 1.2.0"},
     {:phoenix_pubsub, "~> 1.0"},
     {:phoenix_ecto, "~> 3.0"},
     {:postgrex, ">= 0.0.0"},
     {:phoenix_html, "~> 2.6"},
     {:phoenix_live_reload, "~> 1.0", only: :dev},
     {:gettext, "~> 0.11"},
     {:cowboy, "~> 1.0"},
     {:amqp, "~> 0.1.4"}]
end

What changes I need to make, to have my elixir app work with rabbitMQ?

Thank you

Advertisement

Answer

It is a reported issue in the :amqp project (https://github.com/pma/amqp/issues/28) It fails compilation with Erlang 19. The problem lies in :amqp_client. The last version in the repository is fixed, but it does not exist as a hex package yet.

Update 2016-08-16:

If you want to use AMQP with Erlang 19 in your project just add the current :amqp_client dependency to override the one that comes with AMQP:

def deps do
  [{:amqp_client, git: "https://github.com/jbrisbin/amqp_client.git", override: true},
   {:amqp, "~> 0.1.4"}]
end

For this concrete example you should have something like:

defp deps do
  [{:phoenix, "~> 1.2.0"},
   {:phoenix_pubsub, "~> 1.0"},
   {:phoenix_ecto, "~> 3.0"},
   {:postgrex, ">= 0.0.0"},
   {:phoenix_html, "~> 2.6"},
   {:phoenix_live_reload, "~> 1.0", only: :dev},
   {:gettext, "~> 0.11"},
   {:cowboy, "~> 1.0"},
   {:amqp_client, git: "https://github.com/jbrisbin/amqp_client.git", override: true},
   {:amqp, "~> 0.1.4"]
end

Important: You should override the :amqp_client dependency in projects that use AMQP event if their mix file is already overriding the dependency.

I hope this helps.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement