Jido.Signal.Dispatch.PubSub (Jido v1.1.0-rc.2)
View SourceAn 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
@type delivery_error() :: :pubsub_not_found | term()
@type delivery_opts() :: [target: delivery_target(), topic: String.t()]
@type delivery_target() :: atom()
Functions
@spec deliver(Jido.Signal.t(), delivery_opts()) :: :ok | {:error, delivery_error()}
Broadcasts a signal through Phoenix.PubSub.
Parameters
signal
- The signal to broadcastopts
- Validated options fromvalidate_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
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