PhoenixMicro.Transport.Memory (PhoenixMicro v1.0.0)

Copy Markdown View Source

An in-process pub/sub transport backed by Registry and GenServer.

This transport is:

  • Always available — no external broker required.
  • Used in test environments to avoid broker dependencies.
  • Fully functional — supports publish, subscribe, ack, nack, wildcard topics, consumer groups, and dead-letter queues.
  • Observable — emits all standard Telemetry events.

Wildcard support

Wildcards follow the NATS convention:

  • * matches a single token: "payments.*" matches "payments.created".
  • > matches the rest: "payments.>" matches "payments.created.v2".

Usage in config

config :phoenix_micro, transport: :memory

Usage in tests

setup do
  {:ok, _pid} = start_supervised(PhoenixMicro.Transport.Memory)
  :ok
end

Summary

Functions

Returns a specification to start this module under a supervisor.

Clears the message log. Useful between test cases.

Returns all dead-lettered messages.

Returns all messages published since start (useful in tests).

Blocks until at least count messages matching topic have been received.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

clear(server \\ PhoenixMicro.Transport.Memory)

Clears the message log. Useful between test cases.

dlq_messages(server \\ PhoenixMicro.Transport.Memory)

Returns all dead-lettered messages.

messages(server \\ PhoenixMicro.Transport.Memory)

Returns all messages published since start (useful in tests).

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

wait_for_messages(topic, count \\ 1, timeout \\ 5000)

@spec wait_for_messages(String.t(), pos_integer(), timeout()) :: :ok | :timeout

Blocks until at least count messages matching topic have been received.