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

Subscriber helper scaffold.

To easy register the pub_sub consumer in Envio.Registry, one might use this helper to scaffold the registering/unregistering code. It turns the module into the GenServer and provides the handy wrapper for the respective handle_info/2. One might override handle_envio to implement custom handling.

The typical usage would be:

defmodule PubSubscriber do
  use Envio.Subscriber, channels: [{PubPublisher, :foo}]

  def handle_envio(message, state) do
    with {:noreply, state} <- super(message, state) do
      IO.inspect({message, state}, label: "Received message")
      {:noreply, state}
    end
  end
end

If channels are not specified as a parameter in call to use Envio.Subscriber, this module might subscribe to any publisher later with subscribe/1:

PubSubscriber.subscribe(%Envio.Channel{source: PubPublisher, name: :foo})

For how to publish, see Envio.Publisher.

Summary

Callbacks

The callback to subscribe stuff to Envio.

Callbacks

Link to this callback

handle_envio(message, state)

View Source
@callback handle_envio(message :: :timeout | term(), state :: Envio.State.t()) ::
  {:noreply, new_state}
  | {:noreply, new_state, timeout() | :hibernate | {:continue, term()}}
  | {:stop, reason :: term(), new_state}
when new_state: Envio.State.t()

The callback to subscribe stuff to Envio.