Commit 26fdc92e authored by Miguel Basticioto's avatar Miguel Basticioto
Browse files

feat: criado sender

parent baeb5f06
defmodule NotificationDispatcher do
@moduledoc """
Documentation for `NotificationDispatcher`.
"""
def hello do
:world
end
end
defmodule NotificationDispatcher.Sender do
@minute 60000
def send_message(channel_name, message, offset) do
options = [
host: Application.fetch_env!(:notification_dispatcher, :rabbitmq_host),
port: 5672,
virtual_host: "/",
username: Application.fetch_env!(:notification_dispatcher, :rabbitmq_username),
password: Application.fetch_env!(:notification_dispatcher, :rabbitmq_password)
]
{:ok, amqpconn} = AMQP.Connection.open(options)
{:ok, chan} = AMQP.Channel.open(amqpconn)
headers = [{"x-delay", :long, @minute * offset}]
AMQP.Basic.publish(
chan,
channel_name,
"",
message,
persistent: true,
headers: headers
)
AMQP.Connection.close(amqpconn)
end
end
\ No newline at end of file
......@@ -21,9 +21,8 @@ defmodule NotificationDispatcher.MixProject do
# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:ecto_sql, "~> 3.1"}
# {:dep_from_hexpm, "~> 0.3.0"},
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
{:ecto_sql, "~> 3.1"},
{:amqp, "~> 1.6.0"}
]
end
end
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment