View Source Envio.Publisher behaviour (envio v1.0.0)

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).

Since v0.8.0 Envío supports Phoenix.PubSub for distributed message broadcasting.

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

For how to subscribe, see Envio.Subscriber.

Summary

Callbacks

The callback to publish stuff to Envio.

Callbacks

Link to this callback

broadcast(channel, message)

View Source
@callback broadcast(channel :: binary() | atom(), message :: map()) :: :ok

The callback to publish stuff to Envio.