View Source RabbitMQStream.Publisher (rabbitmq_stream v0.2.1)

RabbitMQStream.Publisher allows you to define modules or processes that publish messages to a single stream.

defining-a-publisher-module

Defining a publisher Module

A standalone publisher module can be defined with:

defmodule MyApp.MyPublisher do
  use RabbitMQStream.Publisher,
    stream_name: "my-stream",
    connection: MyApp.MyConnection
end

After adding it to your supervision tree, you can publish messages with:

MyApp.MyPublisher.publish("Hello, world!")

You can add the publisher to your supervision tree as follows this:

def start(_, _) do
  children = [
    # ...
    MyApp.MyPublisher
  ]

  opts = # ...
  Supervisor.start_link(children, opts)
end

The standalone publisher starts its own RabbitMQStream.Connection, declaring itself and fetching its most recent publishing_id, and declaring the stream, if it does not exist.

configuration

Configuration

The RabbitMQStream.Publisher accepts the following options:

  • stream_name - The name of the stream to publish to. Required.
  • reference_name - The string which is used by the server to prevent Duplicate Message. Defaults to __MODULE__.Publisher.
  • connection - The identifier for a RabbitMQStream.Connection.

You can also declare the configuration in your config.exs:

config :rabbitmq_stream, MyApp.MyPublisher,
  stream_name: "my-stream",
  connection: MyApp.MyConnection