From 0419a15a175be92b26a2fff75d80cf3fe07723cf Mon Sep 17 00:00:00 2001 From: Victor Gaiva <13839490+VictorGaiva@users.noreply.github.com> Date: Thu, 21 Mar 2024 01:11:49 -0300 Subject: [PATCH] doc: Minor documentation updates --- README.md | 42 +++++++++++++++----------------- guides/concepts/super-streams.md | 4 ++- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 68df92f..7ffcc86 100644 --- a/README.md +++ b/README.md @@ -37,9 +37,27 @@ def deps do end ``` -## Usage +### Producing -### Consuming from Stream +RabbitMQ Streams protocol needs a static `:reference_name` per producer. This is used to prevent message duplication. For this reason, each stream needs, for now, a static module to publish messages, which keeps track of its own `publishing_id`. + +You can define a `Producer` module like this: + +```elixir +defmodule MyApp.MyProducer do + use RabbitMQStream.Producer, + stream_name: "stream-01", + connection: MyApp.MyConnection +end +``` + +Then you can publish messages to the stream: + +```elixir +MyApp.MyProducer.publish("Hello World") +``` + +## Consuming First you define a connection @@ -80,26 +98,6 @@ def handle_info({:deliver, %RabbitMQStream.Message.Types.DeliverData{} = deliver end ``` -### Publishing to Stream - -RabbitMQ Streams protocol needs a static `:reference_name` per producer. This is used to prevent message duplication. For this reason, each stream needs, for now, a static module to publish messages, which keeps track of its own `publishing_id`. - -You can define a `Producer` module like this: - -```elixir -defmodule MyApp.MyProducer do - use RabbitMQStream.Producer, - stream_name: "stream-01", - connection: MyApp.MyConnection -end -``` - -Then you can publish messages to the stream: - -```elixir -MyApp.MyProducer.publish("Hello World") -``` - ### Configuration The configuration for the connection can be set in your `config.exs` file: diff --git a/guides/concepts/super-streams.md b/guides/concepts/super-streams.md index 86c3b80..3d68653 100644 --- a/guides/concepts/super-streams.md +++ b/guides/concepts/super-streams.md @@ -15,6 +15,7 @@ You can declare a consumer as being part of a Single Active Consumer group by pa defmodule Subs1 do use RabbitMQStream.Consumer, stream_name: "super-stream-01", + connection: MyApp.MyConnection, properties: [single_active_consumer: "group-1"] @impl true @@ -40,7 +41,7 @@ Based on the semantics of `single_active_consumer` property, this library implem You can declare SuperStreams with: ```elixir -:ok = RabbitMQStream.Connection.create_super_stream(conn, "my_super_stream", "route-A": ["stream-01", "stream-02"], "route-B": ["stream-03"]) +:ok = MyApp.MyConnection.create_super_stream("my_super_stream", "route-A": ["stream-01", "stream-02"], "route-B": ["stream-03"]) ``` And you can consume from it with: @@ -49,6 +50,7 @@ And you can consume from it with: defmodule MyApp.MySuperConsumer do use RabbitMQStream.SuperConsumer, initial_offset: :next, + connection: MyApp.MyConnection, super_stream: "my_super_stream" @impl true