gnat v0.5.0 Gnat.ConsumerSupervisor
A process that can supervise consumers for you (EXPERIMENTAL)
Note: This module is experimental and may be removed in the 1.0 release depending on what we find as we experiment with other forms of highly available connections.
If you want to subscribe to a few topics and have that subscription last across restarts for you, then this worker can be of help. It also spawns a supervised Task
for each message it receives. This way errors in message processing don’t crash the consumers, but you will still get SASL reports that you can send to services like honeybadger.
To use this just add an entry to your supervision tree like this:
consumer_supervisor_settings = %{
connection_name: :name_of_supervised_connection,
consuming_function: {MyApp.RpcServer, :handle_request},
subscription_topics: [
%{topic: "rpc.MyApp.search", queue_group: "rpc.MyApp.search"},
%{topic: "rpc.MyApp.create", queue_group: "rpc.MyApp.create"},
],
}
worker(Gnat.ConsumerSupervisor, [consumer_supervisor_settings, [name: :rpc_consumer]], shutdown: 30_000)
The second argument is a keyword list that gets used as the GenServer options so you can pass a name that you want to register for the consumer process if you like. The consuming_function
specific which module and function to call when messages arrive. The function will be called with a single argument which is a gnat message just like you get when you call Gnat.sub
directly.
You can have a single consumer that subscribes to multiple topics or multiple consumers that subscribe to different topics and call different consuming functions. It is recommended that your ConsumerSupervisor
s are present later in your supervision tree than your ConnectionSupervisor
. That way during a shutdown the ConsumerSupervisor
can attempt a graceful shutdown of the consumer before shutting down the connection.
Link to this section Summary
Functions
Returns a specification to start this module under a supervisor
Link to this section Functions
Returns a specification to start this module under a supervisor.
See Supervisor
.
start_link(map(), keyword()) :: GenServer.on_start()