ASM.Extensions.PubSub (ASM v0.9.2)

Copy Markdown View Source

Public PubSub extension API.

This domain provides non-blocking event fanout to local or optional external PubSub backends.

Topic strategy:

  • :all -> asm:events
  • :session -> asm:session:<session_id>
  • :run -> asm:session:<session_id>:run:<run_id>

Payload contract:

  • %{schema: "asm.pubsub.event.v1", event: %ASM.Event{}, meta: %{...}}
  • broadcast messages are delivered as {:asm_pubsub, topic, payload}

Summary

Types

adapter_spec()

@type adapter_spec() :: {module(), keyword()}

Functions

all_topic(opts \\ [])

@spec all_topic(keyword()) :: String.t()

broadcaster_plug(broadcaster, opts \\ [])

@spec broadcaster_plug(
  pid(),
  keyword()
) :: {module(), keyword()}

event_callback(broadcaster, opts \\ [])

@spec event_callback(
  pid(),
  keyword()
) :: (ASM.Event.t(), iodata() -> :ok)

flush_broadcaster(broadcaster, timeout \\ 5000)

@spec flush_broadcaster(pid(), timeout()) :: :ok | {:error, ASM.Error.t()}

local_adapter(opts \\ [])

@spec local_adapter(keyword()) :: adapter_spec()

payload_for_event(event, opts \\ [])

@spec payload_for_event(
  ASM.Event.t(),
  keyword()
) :: ASM.Extensions.PubSub.Payload.t()

phoenix_adapter(opts \\ [])

@spec phoenix_adapter(keyword()) :: adapter_spec()

publish(broadcaster, event, publish_opts \\ [])

@spec publish(pid(), ASM.Event.t(), keyword()) :: :ok

run_topic(session_id, run_id, opts \\ [])

@spec run_topic(String.t(), String.t(), keyword()) :: String.t()

session_topic(session_id, opts \\ [])

@spec session_topic(
  String.t(),
  keyword()
) :: String.t()

start_broadcaster(opts \\ [])

@spec start_broadcaster(keyword()) :: GenServer.on_start() | {:error, ASM.Error.t()}

start_local_bus(opts \\ [])

@spec start_local_bus(keyword()) :: GenServer.on_start() | {:error, ASM.Error.t()}

subscribe(invalid_adapter, topic)

@spec subscribe(adapter_spec(), String.t()) :: :ok | {:error, ASM.Error.t()}

topics_for_event(event, opts \\ [])

@spec topics_for_event(
  ASM.Event.t(),
  keyword()
) :: {:ok, [String.t()]} | {:error, ASM.Error.t()}