Lux.Signal.Router behaviour (Lux v0.3.0)

View Source

Defines the behaviour for signal routing between agents.

Routers are responsible for:

  • Validating signals before delivery
  • Finding appropriate target agents
  • Delivering signals to target agents
  • Supporting subscriptions to signal delivery events

Different implementations can handle routing in various ways:

  • Local routing between agents in the same BEAM VM
  • Remote routing to agents in different nodes
  • External routing to agents in different systems/providers

Summary

Callbacks

Routes a signal to its target agent. Returns :ok if the signal was accepted for routing.

Starts a router process.

Subscribes to future signal delivery events. Subscribers will receive messages in the format: {:signal_delivered, signal_id} | {:signal_failed, signal_id, reason}

Unsubscribes from signal delivery events.

Types

router()

@type router() :: module() | {module(), term()}

routing_options()

@type routing_options() :: keyword()

Callbacks

route(signal, opts)

@callback route(signal :: Lux.Signal.t(), opts :: routing_options()) ::
  :ok | {:error, term()}

Routes a signal to its target agent. Returns :ok if the signal was accepted for routing.

start_link(opts)

@callback start_link(opts :: keyword()) :: GenServer.on_start()

Starts a router process.

subscribe(signal_id, opts)

@callback subscribe(signal_id :: String.t(), opts :: routing_options()) ::
  :ok | {:error, term()}

Subscribes to future signal delivery events. Subscribers will receive messages in the format: {:signal_delivered, signal_id} | {:signal_failed, signal_id, reason}

unsubscribe(signal_id, opts)

@callback unsubscribe(signal_id :: String.t(), opts :: routing_options()) ::
  :ok | {:error, term()}

Unsubscribes from signal delivery events.

Functions

route(signal, opts \\ [])

subscribe(signal_id, opts \\ [])

unsubscribe(signal_id, opts \\ [])