elsa v0.10.0 Elsa.Supervisor
Top-level supervisor that orchestrates all other components of the Elsa library. Allows for a single point of integration into your application supervision tree and configuration by way of a series of nested keyword lists
Components not needed by a running application (if your application only consumes messages from Kafka and never producers back to it) can be safely omitted from the configuration.
Link to this section Summary
Functions
Returns a specification to start this module under a supervisor.
Callback invoked to start the supervisor and during hot code upgrades.
Defines a connection for locating the Elsa Registry process.
Starts the top-level Elsa supervisor and links it to the current process. Starts a brod client and a custom process registry by default and then conditionally starts and takes supervision of any brod group-based consumers or producer processes defined.
Link to this section Functions
child_spec(init_arg)
Returns a specification to start this module under a supervisor.
See Supervisor
.
init(args)
Callback invoked to start the supervisor and during hot code upgrades.
Developers typically invoke Supervisor.init/2
at the end of their
init callback to return the proper supervision flags.
Callback implementation for Supervisor.init/1
.
registry(connection)
Defines a connection for locating the Elsa Registry process.
start_link(args)
start_link(keyword()) :: GenServer.on_start()
start_link(keyword()) :: GenServer.on_start()
Starts the top-level Elsa supervisor and links it to the current process. Starts a brod client and a custom process registry by default and then conditionally starts and takes supervision of any brod group-based consumers or producer processes defined.
Options
:endpoints
- Required. Keyword list of kafka brokers. ex.[localhost: 9092]
:connection
- Required. Atom used to track kafka connection.:config
- Optional. Client configuration options passed to brod.:producer
- Optional. Can be a single producer configuration of multiples in a list.:group_consumer
- Optional. Group consumer configuration.
Producer Config
:topic
- Required. Producer will be started for configured topic.:config
- Optional. Producer configuration options passed tobrod_producer
.
Group Consumer Config
:group
- Required. Name of consumer group.:topics
- Required. List of topics to subscribe to.:handler
- Required. Module that implements Elsa.Consumer.MessageHandler behaviour.:handler_init_args
- Optional. Any args to be passed to init function in handler module.:assignment_received_handler
- Optional. Arity 4 Function that will be called with any partition assignments. Return:ok
to for assignment to be subscribed to. Return{:error, reason}
to stop subscription. Arguments are group, topic, partition, generation_id.:assignments_revoked_handler
- Optional. Zero arity function that will be called when assignments are revoked. All workers will be shutdown before callback is invoked and must return:ok
.:direct_ack
- Optional. Boolean,true
indicates to bypassbrod_group_coordinator
and ack directly to kafka. Defaults tofalse
.:config
- Optional. Consumer configuration options passed tobrod_consumer
.
Example
Elsa.Supervisor.start_link([
endpoints: [localhost: 9092],
connection: :conn,
producer: [topic: "topic1"],
group_consumer: [
group: "example-group",
topics: ["topic1"],
handler: ExampleHandler,
config: [
begin_offset: :earliest,
offset_reset_policy: :reset_to_earliest
]
]
])