View Source Elsa.Consumer.Worker (Elsa.fi v3.5.0)

Defines the worker GenServer that is managed by the DynamicSupervisor. Workers are instantiated and assigned to a specific topic/partition and process messages according to the specified message handler module passed in from the manager before calling the ack function to notify the cluster the messages have been successfully processed.

self-healing-on-offset_out_of_range

Self-healing on offset_out_of_range

Under brod's default offset_reset_policy: reset_by_subscriber, when a committed offset falls outside the available log (topic recreated, retention truncation, cluster cutover), brod casts a kafka_fetch_error with error_code: :offset_out_of_range and suspends fetching. The worker handles this by re-subscribing in place at config[:begin_offset] (default :latest), which un-suspends brod and resumes consumption without a process restart.

Because the reset jumps to the policy target, messages between the stale committed offset and the reset target may be skipped. Callers running non-idempotent handlers should be aware that a reset can cause records to be dropped (with :latest) — and conversely, replay/double-processing is possible if you choose :earliest. Callers needing replay should set begin_offset: :earliest and design their handlers to tolerate reprocessing.

This self-heal only applies under reset_by_subscriber. With the :reset_to_latest / :reset_to_earliest policies brod resets internally and never casts the error, so the worker's offset_out_of_range clause never fires.

If re-subscribe fails after exhausting retries, the worker stops with {:resubscribe_failed, reason} (fail loud — never silently stall). Group consumers recover via Elsa.Group.Manager's monitor, which restarts the worker. Simple consumers (Elsa.Consumer.Worker.Initializer) are restart: :temporary with no monitor, so a stopped worker is not restarted automatically — they require external supervision. This is an accepted, documented limitation: the in-place re-subscribe happy path is what protects simple consumers; the :stop is only the failure path.

Link to this section Summary

Functions

Returns a specification to start this module under a supervisor.

Callback implementation for GenServer.init/1.

Start the worker process and init the state with the given config.

Link to this section Types

@type init_opts() :: [
  connection: Elsa.connection(),
  topic: Elsa.topic(),
  partition: Elsa.partition(),
  generation_id: non_neg_integer(),
  begin_offset: non_neg_integer(),
  handler: module(),
  handler_init_args: term(),
  config: :brod.consumer_config()
]

Link to this section Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

handle_continue(atom, state)

View Source

Callback implementation for GenServer.handle_continue/2.

Callback implementation for GenServer.init/1.

Link to this macro

kafka_fetch_error(args \\ [])

View Source (macro)
Link to this macro

kafka_fetch_error(record, args)

View Source (macro)
Link to this macro

kafka_message_set(args \\ [])

View Source (macro)
Link to this macro

kafka_message_set(record, args)

View Source (macro)
@spec start_link(init_opts()) :: GenServer.on_start()

Start the worker process and init the state with the given config.