Sequin (sequin v0.1.0) View Source

A lightweight Elixir SDK for sending, receiving, and acknowledging messages in Sequin streams.

Installation

Sequin can be installed by adding sequin to your list of dependencies in mix.exs:

def deps do
  [
    {:sequin, "~> 0.1.0"}
  ]
end

Configuration

To use Sequin in your application, you'll need to configure it in your config.exs file. Add the following configuration:

# config/config.exs

config :sequin,
  base_url: System.get_env("SEQUIN_URL") || "http://localhost:7673"

By default, the Client is initialized using Sequin's default host and port in local development: http://localhost:7673

Usage

You'll predominantly use Sequin to send, receive, and acknowledge messages in Sequin streams:

# Define your stream and consumer
stream = "your-stream-name"
consumer = "your-consumer-name"

# Send a message
case Sequin.send_message(stream, "test.1", "Hello, Sequin!") do
  {:ok, %{published: 1}} ->
    IO.puts("Message sent successfully")

  {:error, error} ->
    IO.puts("Error sending message: #{Exception.message(error)}")
end

# Receive a message
with {:ok, %{message: message, ack_id: ack_id}} <- Sequin.receive_message(stream, consumer),
     :ok <- YourApp.process_message(message),
     :ok <- Sequin.ack_message(stream, consumer, ack_id) do
  IO.puts("Received and acked message: #{inspect(message)}")
else
  {:ok, nil} ->
    IO.puts("No messages available")

  {:error, error} ->
    IO.puts("Error: #{Exception.message(error)}")
end

Link to this section Summary

Functions

After processing a message, you can acknowledge it using ack_message/3

After processing messages, you can acknowledge them using ack_messages/3

Creates a new consumer for a stream.

For a full list of options, see: Sequin.Stream

Nacks a single message for a consumer by ack_id.

Nacks a list of messages for a consumer by ack_id.

Receive a single message from a consumer.

Receive a batch of messages from a consumer.

Send a message to a stream.

Send a batch of messages (max 1,000).

Link to this section Functions

Link to this function

ack_message(stream, consumer, ack_id)

View Source

Specs

ack_message(
  stream :: String.t(),
  consumer :: String.t(),
  ack_id :: String.t()
) :: :ok | {:error, Exception.t()}

After processing a message, you can acknowledge it using ack_message/3:

Acks a single message for a consumer by ack_id.

Link to this function

ack_messages(stream, consumer, ack_ids)

View Source

Specs

ack_messages(
  stream :: String.t(),
  consumer :: String.t(),
  ack_ids :: [String.t()]
) :: :ok | {:error, Exception.t()}

After processing messages, you can acknowledge them using ack_messages/3:

Acks a list of messages for a consumer by ack_id.

Link to this function

create_consumer(stream, name, filter, opts \\ [])

View Source

Creates a new consumer for a stream.

For a full list of options, see: Sequin.Consumer

Link to this function

create_stream(name, options \\ [])

View Source

Specs

create_stream(stream :: String.t(), opts :: Keyword.t()) ::
  {:ok, Sequin.Stream.t()} | {:error, Exception.t()}

For a full list of options, see: Sequin.Stream

Link to this function

delete_consumer(stream, consumer)

View Source

Specs

delete_consumer(stream :: String.t(), consumer :: String.t()) ::
  :ok | {:error, Exception.t()}

Specs

delete_stream(stream :: String.t()) ::
  {:ok, %{deleted: true, id: String.t()}} | {:error, Exception.t()}
Link to this function

nack_message(stream, consumer, ack_id)

View Source

Specs

nack_message(
  stream :: String.t(),
  consumer :: String.t(),
  ack_id :: String.t()
) :: :ok | {:error, Exception.t()}

Nacks a single message for a consumer by ack_id.

Link to this function

nack_messages(stream, consumer, ack_ids)

View Source

Specs

nack_messages(
  stream :: String.t(),
  consumer :: String.t(),
  ack_ids :: [String.t()]
) :: :ok | {:error, Exception.t()}

Nacks a list of messages for a consumer by ack_id.

Link to this function

receive_message(stream, consumer)

View Source

Specs

receive_message(stream :: String.t(), consumer :: String.t()) ::
  {:ok, %{message: Sequin.Message.t(), ack_id: String.t()}}
  | {:error, Exception.t()}

Receive a single message from a consumer.

Link to this function

receive_messages(stream, consumer, opts \\ [])

View Source

Specs

receive_messages(
  stream :: String.t(),
  consumer :: String.t(),
  opts :: [{:batch_size, integer()}]
) ::
  {:ok, [%{message: Sequin.Message.t(), ack_id: String.t()}]}
  | {:error, Exception.t()}

Receive a batch of messages from a consumer.

batch_size defaults to 10.

Link to this function

send_message(stream, key, data)

View Source

Specs

send_message(stream :: String.t(), key :: String.t(), data :: String.t()) ::
  {:ok, %{published: integer()}} | {:error, Exception.t()}

Send a message to a stream.

Link to this function

send_messages(stream, messages)

View Source

Specs

send_messages(
  stream :: String.t(),
  messages :: [%{key: String.t(), data: String.t()}]
) :: {:ok, %{published: integer()}} | {:error, Exception.t()}

Send a batch of messages (max 1,000).

send_messages/2 is all or nothing. Either all the messages are successfully sent, or none of the messages are sent.