Yggdrasil for RabbitMQ v5.0.2 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
Returns a specification to start this module under a supervisor.
Publishes a message
in a channel
using a publisher
server. Optionally,
it receives a list of options (options expected by AMQP.Basic.publish/5
).
Starts a RabbitMQ publisher with a namespace
for the configuration.
Additionally, you can add GenServer
options
.
Stops a RabbitMQ publisher
. Optionally, receives a stop reason
(defaults
to :normal
) and a timeout
in milliseconds (defaults to :infinity
).
Link to this section Functions
Returns a specification to start this module under a supervisor.
See Supervisor
.
publish(publisher, channel, message, options \\ [])
View Sourcepublish(GenServer.name(), Yggdrasil.Channel.t(), term(), Keyword.t()) :: :ok | {:error, term()}
Publishes a message
in a channel
using a publisher
server. Optionally,
it receives a list of options (options expected by AMQP.Basic.publish/5
).
start_link(namespace, options \\ [])
View Sourcestart_link(term(), GenServer.options()) :: GenServer.on_start()
Starts a RabbitMQ publisher with a namespace
for the configuration.
Additionally, you can add GenServer
options
.
stop(publisher, reason \\ :normal, timeout \\ :infinity)
View Sourcestop(GenServer.name(), term(), non_neg_integer() | :infinity) :: :ok
Stops a RabbitMQ publisher
. Optionally, receives a stop reason
(defaults
to :normal
) and a timeout
in milliseconds (defaults to :infinity
).