Packages

Library used for integration with the rabbitmq for dispatching notification messages to consuming services.

Current section

Files

Jump to
Raw

lib/sender.ex

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