View Source Getting Started

installation

Installation

First add RabbitMQ to your mix.exs dependencies:

def deps do
  [
    {:rabbitmq_stream, "~> 0.2.0"},
    # ...
  ]
end

subscribing-to-stream

Subscribing to stream

First you define a connection

defmodule MyApp.MyConnection
  use RabbitMQStream.Connection
end

Then you can subscribe to messages from a stream:

{:ok, _subscription_id} = MyApp.MyConnection.subscribe("stream-01", self(), :next, 999)

publishing-to-stream

Publishing to stream

RabbitMQ Streams protocol needs a static :reference_name per publisher. 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 Publisher module like this:

defmodule MyApp.MyPublisher
  use RabbitMQStream.Publisher,
    stream: "stream-01",
    connection: MyApp.MyConnection
end

Then you can publish messages to the stream:

MyApp.MyPublisher.publish("Hello World")