envio v0.3.2 Envio.Subscriber behaviour View Source

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.

Link to this section Summary

Callbacks

The callback to subscribe stuff to Envio

Link to this section Callbacks

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

The callback to subscribe stuff to Envio.