yggdrasil v3.3.1 Yggdrasil.Publisher.Adapter.RabbitMQ View Source

Yggdrasil publisher adapter for RabbitMQ. The name of the channel should be a tuple with the name of the exchange and the routing key. The exchange should be a topic (or any exhange that redirect to topic) e.g:

Subscription to channel:

iex(1)> name = {"amq.topic", "channel"}
iex(2)> channel = %Yggdrasil.Channel{name: name, adapter: :rabbitmq}
iex(3)> Yggdrasil.subscribe(channel)
:ok
iex(4)> flush()
{:Y_CONNECTED, %Yggdrasil.Channel{name: {"amq.topic", "channel"}, (...)}}

Publishing message:

iex(5)> Yggdrasil.publish(channel, "foo")
:ok

Subscriber receiving message:

iex(6)> flush()
{:Y_EVENT, %Yggdrasil.Channel{name: {"amq.topic", "channel"}, (...)}, "foo"}

The subscriber can also unsubscribe from the channel:

iex(7)> Yggdrasil.unsubscribe(channel)
:ok
iex(8)> flush()
{:Y_DISCONNECTED, %Yggdrasil.Channel{name: {"amq.topic", "channel"}, (...)}}

Link to this section Summary

Functions

Publishes a message in a channel using a publisher and optional options. The options argument is a Keyword list of options expected by AMQP.Basic.publish/5 in its fifth argument

Starts a RabbitMQ publisher with a namespace. Additianally you can add GenServer options

Stops a RabbitMQ publisher

Link to this section Functions

Link to this function publish(publisher, channel, message, options \\ []) View Source
publish(GenServer.server(), Yggdrasil.Channel.t(), term(), Keyword.t()) ::
  :ok | {:error, term()}

Publishes a message in a channel using a publisher and optional options. The options argument is a Keyword list of options expected by AMQP.Basic.publish/5 in its fifth argument.

Link to this function start_link(namespace, options \\ []) View Source
start_link(term(), GenServer.options()) :: GenServer.on_start()

Starts a RabbitMQ publisher with a namespace. Additianally you can add GenServer options.

Stops a RabbitMQ publisher.