All checks were successful
Build and Publish / build-release (push) Successful in 1m26s
21 lines
499 B
Elixir
21 lines
499 B
Elixir
defmodule WorkloadService.MessageBus do
|
|
use AMQP
|
|
|
|
def publish(exchange, routing_key, event) do
|
|
payload = Jason.encode!(event)
|
|
|
|
:ok =
|
|
AMQP.Basic.publish(channel(), exchange, routing_key, payload,
|
|
content_type: "application/json",
|
|
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!(:workload_service, :amqp_url)
|
|
end |