yggdrasil logo

Build StatusHex pmhex.pm downloads

Yggdrasil is an immense mythical tree that connects the nine worlds in Norse cosmology.

Yggdrasil is an agnostic publisher/subscriber. Some of the available adapters are the following:

For more information on how to use them, check the respective repository.

Small Example

The following example uses the Elixir distribution to send the messages:

iex(1)> channel = %Yggdrasil.Channel{name: "channel"}
iex(2)> Yggdrasil.subscribe(channel)
iex(3)> flush()
{:Y_CONNECTED, %Yggdrasil.Channel{(...)}}

and to publish a for the subscribers:

iex(4)> Yggdrasil.publish(channel, "message")
iex(5)> flush()
{:Y_EVENT, %Yggdrasil.Channel{(...)}, "message"}

When the subscriber wants to stop receiving messages, then it can unsubscribe from the channel:

iex(6)> Yggdrasil.unsubscribe(channel)
iex(7)> flush()
{:Y_DISCONNECTED, %Yggdrasil.Channel{(...)}}

Channels

The struct %Yggdrasil.Channel{} is used for subscription and message publishing e.g:

%Yggdrasil.Channel{
name: term(), # Depends on the adapter.
adapter: atom(), # Adapter's name.
transformer: atom(), # Transformer's name.
backend: atom(), # Backend's name.
namespace: atom() # Adapter's configuration namespace.
}

Adapters

An adapter is a process that connects to a service and distributes its messages among the subscribers of a channel. The following repositories have some of the available adapters:

For more information on how to use them, check the corresponding repository documentation.

Transformers

A transformer is the implementation of the behaviour Yggdrasil.Transformer. In essence implements two functions:

Yggdrasil has two implemented transformers:

Backends

A backend is the implementation of the behaviour Yggdrasil.Backend. The module is in charge of distributing the messages with a certain format inside Yggdrasil. Currently, there is only one backend, :default, and it is used by default in :elixir adapter and the previously mentioned adapters :rabbitmq, :redis and :postgres.

The messages received by the subscribers when using :default backend are:

Configuration

Yggdrasil works out of the box with no special configuration at all. However, it is possible to configure the publisher. Yggdrasil uses Phoenix.PubSub for message distribution and the following are the available options:

The rest of the options are for configuring the publishers and process name registry:

For more information about configuration using OS environment variables check the module Yggdrasil.Settings.

Installation

Yggdrasil is available as a Hex package. To install, add it to your dependencies in your mix.exs file:

def deps do
[{:yggdrasil, "~> 4.1"}]
end

Relevant projects used

Author

Alexander de Sousa.

License

Yggdrasil is released under the MIT License. See the LICENSE file for further details.