View Source RabbitMQStream.Publisher (rabbitmq_stream v0.1.0)
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 aRabbitMQStream.Connection
.