Created
June 29, 2020 06:28
-
-
Save bbtdev/8016ff66d9e2fc924a53e03e389e5648 to your computer and use it in GitHub Desktop.
elixir-rabbitmq-delayed-messages
This file contains hidden or 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
defmodule Testing do | |
@moduledoc """ | |
Documentation for `Testing`. | |
""" | |
@doc """ | |
Hello world. | |
## Examples | |
iex> Testing.hello() | |
:world | |
""" | |
def hello do | |
:world | |
end | |
def rabbit do | |
{:ok, conn} = AMQP.Connection.open() | |
# {:ok, %AMQP.Connection{pid: #PID<0.165.0>}} | |
{:ok, chan} = AMQP.Channel.open(conn) | |
# {:ok, %AMQP.Channel{conn: %AMQP.Connection{pid: #PID<0.165.0>}, pid: #PID<0.177.0>} | |
AMQP.Queue.declare(chan, "test_queue") | |
# {:ok, %{consumer_count: 0, message_count: 0, queue: "test_queue"}} | |
args = [ {"x-delayed-type", :longstr, "direct"} ] | |
AMQP.Exchange.declare(chan, "test_exchange", :"x-delayed-message", arguments: args) | |
# :ok | |
AMQP.Queue.bind(chan, "test_queue", "test_exchange") | |
AMQP.Queue.subscribe(chan, "test_queue", fn payload, _meta -> IO.puts("Received: #{payload}") end) | |
# {:ok, "amq.ctag-5L8U-n0HU5doEsNTQpaXWg"} | |
args = [ {"x-delay", :long, 2000} ] | |
AMQP.Basic.publish(chan, "test_exchange", "", "Hello, World!", headers: args) | |
# :ok | |
# Received: Hello, World! | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment