Skip to content

Instantly share code, notes, and snippets.

@leikind
Created November 9, 2017 22:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leikind/7f1721d706646343527962e233c1debd to your computer and use it in GitHub Desktop.
Save leikind/7f1721d706646343527962e233c1debd to your computer and use it in GitHub Desktop.
case Connection.open(amqp_url) do
{:error, reason} -> # pattern matching
Logger.error(["Cannot establish connection to RabbitMQ, reason:", inspect(reason)])
{:error, reason}
{:ok, connection} -> # pattern matching
{:ok, channel} = Channel.open(connection) # pattern matching
Exchange.declare(channel, @exchange, :fanout)
{:ok, %{queue: queue_name}} = Queue.declare(channel, "", exclusive: true) # pattern matching
Queue.bind(channel, queue_name, @exchange)
{:ok, _consumer_tag} = Basic.consume(channel, queue_name, nil, no_ack: true) # pattern matching
channel
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment