Framework.Sequencer.BehaviorConsumer behaviour (Framework v0.5.0)

View Source

Behavior for sequencer event consumers.

Defines the contract that all consumers must implement for consumer conformance. Consumers must:

  1. Persist cursors in consumer_cursors table
  2. Resume from > last_processed_sequence after restart
  3. Handle sequence gaps without failure
  4. Remain stable during NOTIFY storms
  5. Use range-scan for correctness (NOTIFY as wake hint only)
  6. Never infer order from timestamps - sequence only

Consumer Implementation Example

defmodule MyApp.EventConsumer do
  use Framework.Sequencer.Consumer

  def handle_events(events) do
    Enum.each(events, &process_event/1)
    :ok
  end

  defp process_event(event) do
    # Process event payload
    :ok
  end
end

Summary

Callbacks

Process a batch of events in sequence order.

Callbacks

handle_events(list)

@callback handle_events([map()]) :: :ok | {:error, any()}

Process a batch of events in sequence order.

Events are guaranteed to be in ascending sequence order. Must return :ok on success or {:error, reason} on failure.