envio v0.6.1 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
Link to this section Callbacks
The callback to subscribe stuff to Envio.