HareMq.Publisher (hare_mq v1.4.0)

Copy Markdown

Macro that injects a full RabbitMQ publisher GenServer into the calling module.

Usage

defmodule MyApp.Producer do
  use HareMq.Publisher,
    routing_key: "my_key",   # required
    exchange: "my_exchange"  # optional; nil publishes to the default exchange
end

Options

OptionRequiredDescription
routing_keyyesAMQP routing key
exchangenoExchange name. Declared durable on connect.
uniquenoDeduplication config: [period: ttl_ms_or_infinity, keys: [:field]]
connection_namenoNamed connection for multi-vhost use (default {:global, HareMq.Connection})
dedup_cache_namenoNamed dedup cache (default {:global, HareMq.DedupCache})

Return values of publish_message/1

  • :ok — message accepted by the broker.
  • {:error, :not_connected} — no active channel yet.
  • {:error, {:encoding_failed, reason}} — map could not be JSON-encoded.
  • {:ok, :duplicate} — deduplication prevented publishing (message already seen).