23 lines
537 B
Elixir
23 lines
537 B
Elixir
defmodule PolicyService.MessageBus do
|
|
use AMQP
|
|
|
|
def publish(routing_key, event) do
|
|
payload = Jason.encode!(event)
|
|
|
|
:ok =
|
|
AMQP.Basic.publish(channel(), "policy_service.events", routing_key, payload,
|
|
content_type: "application/json",
|
|
# survives RabbitMQ restart
|
|
persistent: true
|
|
)
|
|
end
|
|
|
|
defp channel do
|
|
{:ok, conn} = AMQP.Connection.open(amqp_url())
|
|
{:ok, chan} = AMQP.Channel.open(conn)
|
|
chan
|
|
end
|
|
|
|
defp amqp_url, do: Application.fetch_env!(:policy_service, :amqp_url)
|
|
end
|