PhoenixMicro.Producer (PhoenixMicro v1.0.0)

Copy Markdown View Source

High-level message producer with batching, async fire-and-forget, and sync-with-ack publishing.

Usage

# Async fire-and-forget
PhoenixMicro.Producer.publish("payments.created", %{amount: 100})

# Sync with confirmation
:ok = PhoenixMicro.Producer.publish_sync("payments.created", %{amount: 100})

# Batch publish
messages = [
  {"payments.created", %{amount: 100}},
  {"payments.created", %{amount: 200}}
]
PhoenixMicro.Producer.publish_batch(messages)

Summary

Functions

Returns a specification to start this module under a supervisor.

Publishes a message asynchronously (fire-and-forget). Returns immediately; does not wait for broker acknowledgment.

Publishes multiple messages, automatically batching them.

Publishes a message synchronously, waiting for broker confirmation. Returns :ok or {:error, reason}.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

publish(topic, payload, opts \\ [])

@spec publish(String.t(), term(), keyword()) :: :ok

Publishes a message asynchronously (fire-and-forget). Returns immediately; does not wait for broker acknowledgment.

publish_batch(messages, opts \\ [])

@spec publish_batch(
  [{String.t(), term()}],
  keyword()
) :: :ok

Publishes multiple messages, automatically batching them.

publish_sync(topic, payload, opts \\ [])

@spec publish_sync(String.t(), term(), keyword()) :: :ok | {:error, term()}

Publishes a message synchronously, waiting for broker confirmation. Returns :ok or {:error, reason}.

start_link(opts \\ [])

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