Jido.Bus.Adapters.PubSub (Jido v1.1.0-rc)

View Source

A Jido Bus adapter implementation using Phoenix.PubSub for simple pub/sub messaging.

This adapter provides basic publish/subscribe functionality without persistence or replay capabilities. It is suitable for scenarios where you need lightweight message distribution without message history.

Features

  • Simple publish/subscribe messaging using Phoenix.PubSub
  • Support for stream-based subscriptions
  • Auto-cleanup of subscriptions when subscribers terminate
  • No message persistence or replay capabilities

Configuration

The adapter requires a Phoenix.PubSub server to be started. This is handled automatically when starting the adapter through child_spec/2.

Usage

# Start the bus with the PubSub adapter
{:ok, children, bus} = Jido.Bus.Adapters.PubSub.child_spec(MyApp, [])
Supervisor.start_link(children, strategy: :one_for_one)

# Subscribe to a stream
:ok = Jido.Bus.subscribe(bus, "my-stream")

# Publish signals
:ok = Jido.Bus.publish(bus, "my-stream", :any_version, [signal], [])

# Receive signals
receive do
  {:signal, signal} -> handle_signal(signal)
end

Limitations

This adapter does not support:

  • Message persistence
  • Stream replay
  • Persistent subscriptions
  • Snapshots
  • Message acknowledgments

Summary

Functions

Not implemented - this adapter does not support message acknowledgments.

Returns the child specification for starting the PubSub adapter.

Not implemented - this adapter does not support snapshots.

Not implemented - this adapter does not support snapshots.

Not implemented - this adapter does not support snapshots.

Not implemented - this adapter does not support stream replay.

Subscribes the current process to a stream.

Not implemented - this adapter does not support persistent subscriptions.

Unsubscribes from a stream or subscription.

Not implemented - this adapter does not support snapshots.

Functions

ack(bus, pid, recorded_signal)

Not implemented - this adapter does not support message acknowledgments.

child_spec(context, opts)

Returns the child specification for starting the PubSub adapter.

Options

  • :name - The name to use for the PubSub server. Defaults to the provided context.

Returns

  • {:ok, children, bus} - A tuple containing the child specs to start and the configured bus.

delete_snapshot(bus, source_id)

Not implemented - this adapter does not support snapshots.

publish(bus, stream_id, expected_version, signals, opts)

Publishes signals to a stream.

The expected_version parameter is ignored as this adapter does not maintain stream versions.

read_snapshot(bus, source_id)

Not implemented - this adapter does not support snapshots.

record_snapshot(bus, snapshot)

Not implemented - this adapter does not support snapshots.

replay(bus, stream_id, start_version, batch_size)

Not implemented - this adapter does not support stream replay.

subscribe(bus, stream_id)

Subscribes the current process to a stream.

subscribe_persistent(bus, stream_id, subscription_name, subscriber, start_from, opts)

Not implemented - this adapter does not support persistent subscriptions.

unsubscribe(bus, subscription)

Unsubscribes from a stream or subscription.

When given a PID, returns :ok since PubSub handles cleanup automatically. When given a stream_id, unsubscribes the current process from that stream.

unsubscribe(bus, one, two)

Not implemented - this adapter does not support snapshots.