AshDispatch.Transport.Registry (AshDispatch v0.5.1)

View Source

Compile-time aggregator over AshDispatch.Transport implementations.

The dispatcher routes by channel.transport atom (:oban, :email, …); this module owns the atom => module mapping and the skip_receipt? lookup. Each known transport is listed below in @transports; adding one is a single-line addition + a new transport file that uses AshDispatch.Transport.

Why compile-time

At runtime, Dispatcher.dispatch_to_transport/4 is hot-path — every event fire passes through it. A compile-time Map.new from the module list avoids any runtime introspection cost. The Map is module-attribute-frozen; lookups are constant time.

Why hardcoded module list (not auto-discovery)

We could walk :application.get_key(:ash_dispatch, :modules) and filter implementers of the behaviour, but:

  1. Boot order matters — the dispatcher could be invoked before transport modules finish loading, producing a partial registry.
  2. AshDispatch is a library; its consumers can't add their own transports today (only the 8 listed here). If that changes, this module evolves to a Spark DSL-driven registry.

Today's static list is the right shape for the actual consumer set.

Summary

Functions

All registered transport modules.

All registered transport atoms.

Find the module that handles a transport atom.

Required event-metadata keys for the transport (F4). Returns [] for unknown atoms — ValidateChannels will already have raised on the unknown transport itself.

Whether the transport skips DeliveryReceipt creation. Returns false for unknown atoms (the safe default — produce a receipt so the audit trail isn't silent).

Functions

all()

@spec all() :: [module()]

All registered transport modules.

atoms()

@spec atoms() :: [atom()]

All registered transport atoms.

module_for(atom)

@spec module_for(atom()) :: {:ok, module()} | :error

Find the module that handles a transport atom.

Returns {:ok, module} or :error for unknown atoms. Callers should :error-handle by logging + skipping the receipt (matches the pre-F1 case-fallthrough behaviour).

required_event_metadata_keys(atom)

@spec required_event_metadata_keys(atom()) :: [atom()]

Required event-metadata keys for the transport (F4). Returns [] for unknown atoms — ValidateChannels will already have raised on the unknown transport itself.

skip_receipt?(atom)

@spec skip_receipt?(atom()) :: boolean()

Whether the transport skips DeliveryReceipt creation. Returns false for unknown atoms (the safe default — produce a receipt so the audit trail isn't silent).