envio v0.3.2 Envio.Publisher behaviour View Source

Publisher helper scaffold.

Simply use Envio.Publisher in the module that should publish messages. The broadcast/2 function becomes available. If the optional channel: argument is passed to use Envio.Publisher, this channel is considered the default one and broadcast/1 function appears to publish directly to the default channel.

The ready-to-copy-paste example of usage would be:

defmodule MyPub do
  use Envio.Publisher, channel: :main

  def publish(channel, what), do: broadcast(channel, what)
  def publish(what), do: broadcast(what)
end

All the subscribers of the particular channel the message was published to, will either receive a message (in the case of :pub_sub) or called back with the function provided on subscription (:dispatch).

The publisher does not wrap :via functionality since it makes not much sense.

For how to subscribe, see Envio.Subscriber.

Link to this section Summary

Callbacks

The callback to publish stuff to Envio

Link to this section Callbacks

Link to this callback broadcast(channel, message) View Source
broadcast(channel :: binary() | atom(), message :: map()) :: :ok

The callback to publish stuff to Envio.