yggdrasil v3.2.1 Yggdrasil.Publisher.Adapter.Elixir View Source

Yggdrasil publisher adapter for Elixir. The name of the channel can be any arbitrary term e.g:

Subscription to channel:

iex(1)> alias Yggdrasil.Channel
iex(2)> sub_channel = %Channel{
...(2)>   name: {:test, "elixir_channel"},
...(2)>   adapter: Yggdrasil.Subscriber.Adapter.Elixir
...(2)> }
iex(3)> Yggdrasil.subscribe(sub_channel)
:ok
iex(4)> flush()
{:Y_CONNECTED, %Channel{name: {:test, "elixir_channel"}, (...)}}

Publishing message:

iex(5)> pub_channel = %Channel{
...(5)>   name: {:test, "elixir_channel"},
...(5)>   adapter: Yggdrasil.Publisher.Adapter.Elixir
...(5)> }
iex(6)> Yggdrasil.publish(pub_channel, "message")
:ok

Subscriber receiving message:

iex(7)> flush()
{:Y_EVENT, %Channel{name: {:test, "elixir_channel"}, (...)}, "message"}

Instead of having sub_channel and pub_channel, the hibrid channel can be used. For the previous example we can do the following:

iex(1)> alias Yggdrasil.Channel
iex(2)> channel = %Channel{name: {:test, "elixir_channel"}, adapter: :elixir}
iex(3)> Yggdrasil.subscribe(channel)
:ok
iex(4)> flush()
{:Y_CONNECTED, %Channel{name: {:test, "elixir_channel"}, (...)}}
iex(5)> Yggdrasil.publish(channel, "message")
:ok
iex(6)> flush()
{:Y_EVENT, %Channel{name: {:test, "elixir_channel"}, (...)}, "message"} 

Link to this section Summary

Functions

Publishes a message in a channel using a publisher

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

Stops an elixir publisher

Link to this section Functions

Link to this function publish(publisher, channel, message) View Source

Publishes a message in a channel using a publisher.

Link to this function start_link(, options \\ []) View Source

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

Stops an elixir publisher.