Jido.Signal.Dispatch.PubSub (Jido Signal v1.0.0)

View Source

An adapter for dispatching signals through Phoenix.PubSub.

This adapter implements the Jido.Signal.Dispatch.Adapter behaviour and provides functionality to broadcast signals through Phoenix.PubSub to all subscribers of a specific topic. It integrates with Phoenix's pub/sub system for distributed message broadcasting.

Configuration Options

  • :target - (required) An atom specifying the PubSub server name
  • :topic - (required) A string specifying the topic to broadcast on

Phoenix.PubSub Integration

The adapter uses Phoenix.PubSub.broadcast/3 to:

  • Broadcast signals to all subscribers of a topic
  • Handle distributed message delivery across nodes
  • Manage subscription-based message routing

Examples

# Basic usage
config = {:pubsub, [
  target: :my_app_pubsub,
  topic: "events"
]}

# Using with specific event topics
config = {:pubsub, [
  target: :my_app_pubsub,
  topic: "user:123:events"
]}

Error Handling

The adapter handles these error conditions:

  • :pubsub_not_found - The target PubSub server is not running
  • Other errors from the Phoenix.PubSub system

Notes

  • Ensure the PubSub server is started in your application supervision tree
  • Topics can be any string, but consider using consistent naming patterns
  • Messages are broadcast to all subscribers, so consider message volume

Summary

Functions

Broadcasts a signal through Phoenix.PubSub.

Validates the PubSub adapter configuration options.

Types

delivery_error()

@type delivery_error() :: :pubsub_not_found | term()

delivery_opts()

@type delivery_opts() :: [target: delivery_target(), topic: String.t()]

delivery_target()

@type delivery_target() :: atom()

Functions

deliver(signal, opts)

@spec deliver(Jido.Signal.t(), delivery_opts()) :: :ok | {:error, delivery_error()}

Broadcasts a signal through Phoenix.PubSub.

Parameters

  • signal - The signal to broadcast
  • opts - Validated options from validate_opts/1

Options

  • :target - (required) Atom identifying the PubSub server
  • :topic - (required) String topic to broadcast on

Returns

  • :ok - Signal broadcast successfully
  • {:error, :pubsub_not_found} - PubSub server not found
  • {:error, reason} - Other broadcast failure

validate_opts(opts)

@spec validate_opts(Keyword.t()) :: {:ok, Keyword.t()} | {:error, term()}

Validates the PubSub adapter configuration options.

Parameters

  • opts - Keyword list of options to validate

Options

  • :target - Must be an atom representing the PubSub server name
  • :topic - Must be a string

Returns

  • {:ok, validated_opts} - Options are valid
  • {:error, reason} - Options are invalid with string reason