I am creating messaging app where app A need to send message to app B using rabbitMQ. I am developing using Phoenix and on rabbitMQ web site I found tutorial how to implement rabbitmq with elixir but I don't know how to use it in my Phoenix app. I tried to add code, which I find on rabbit tutorial web site, to my Phoenix page_controller.ex
defmodule ApplicationA.PageController do
use ApplicationA.Web, :controller
use AMQP
def index(conn, _params) do
{:ok, connection} = AMQP.Connection.open
{:ok, channel} = AMQP.Channel.open(connection)
AMQP.Queue.declare(channel, "hello")
AMQP.Basic.publish(channel, "", "hello", "Hello World!")
IO.puts " [x] Sent 'Hello World!'"
AMQP.Connection.close(connection)
render conn, "index.html"
end
end
but I get this error
no match of right hand side value: {:error, :econnrefused}
in line 6
{:ok, connection} = AMQP.Connection.open
Con somebody help me how I should do this on the good way?