forked from rabbitmq/rabbitmq-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prior to this commit, the RabbitMQ tutorials contained no Elixir examples. One _could_ look at the Erlang examples and adapt them, but that certainly does not result in idiomatic Elixir. This commit adds the first tutorial and an Elixir project file specifying the `amqp` library as the dependency for communicating with RabbitMQ via idiomatic Elixir.
- Loading branch information
Showing
4 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.mix_tasks | ||
mix.lock | ||
/_build | ||
/deps |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
defmodule RabbitmqTutorials.Mixfile do | ||
use Mix.Project | ||
|
||
def project do | ||
[app: :rabbitmq_tutorials, | ||
version: "0.0.1", | ||
elixir: "~> 1.1", | ||
build_embedded: Mix.env == :prod, | ||
start_permanent: Mix.env == :prod, | ||
deps: deps] | ||
end | ||
|
||
# Configuration for the OTP application | ||
# | ||
# Type "mix help compile.app" for more information | ||
def application do | ||
[applications: [:logger, :amqp]] | ||
end | ||
|
||
# Dependencies can be Hex packages: | ||
# | ||
# {:mydep, "~> 0.3.0"} | ||
# | ||
# Or git/path repositories: | ||
# | ||
# {:mydep, git: "https://github.com/elixir-lang/mydep.git", tag: "0.1.0"} | ||
# | ||
# Type "mix help deps" for more examples and options | ||
defp deps do | ||
[ | ||
{:amqp, "~> 0.1.4"}, | ||
] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
defmodule Receive do | ||
def wait_for_messages do | ||
receive do | ||
{:basic_deliver, payload, _meta} -> | ||
IO.puts " [x] Received #{payload}" | ||
wait_for_messages | ||
end | ||
end | ||
end | ||
|
||
{:ok, connection} = AMQP.Connection.open | ||
{:ok, channel} = AMQP.Channel.open(connection) | ||
AMQP.Queue.declare(channel, "hello") | ||
AMQP.Basic.consume(channel, "hello", nil, no_ack: true) | ||
IO.puts " [*] Waiting for messages. To exit press CTRL+C, CTRL+C" | ||
|
||
Receive.wait_for_messages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{: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) |