View Source Seqy (seqy v0.1.1)

Before enqueueing events with Seqy, you need to define a handler for the topic. To define a handler, create a module that use the Seqy.Handler module. Then, implement the handle/1 callback for each event you expect in the sequence.

defmodule MyApp.EventHandler do
  use Seqy.Handler

  require Logger

  def handle(%Seqy.Event{action: :"user.created", args: %{user_id: user_id}}) do
    Logger.info("#{user_id} has been created.")
  end

  def handle(%Seqy.Event{action: :"user.purchased", args: %{user_id: user_id}}) do
    Logger.info("#{user_id} has purchased an item.")
  end

  def handle(%Seqy.Event{action: :"user.paid", args: %{user_id: user_id}}) do
    Logger.info("#{user_id} has paid.")
  end
end

With the event handler ready, we can start enqueueing events to Seqy.

%{action: :"user.created", queue_id: "user_id:1", topic: :user_purchase, args: %{user_id: 1}}
|> Seqy.new()
|> Seqy.enqueue()

An event should have the ff:

  • action - event action that would be used for ordering
  • queue_id - this would be used as the routing key
  • topic - topic of the sequence you declared in your config
  • args - event payload

Link to this section Summary

Functions

Enqueues a new event for processing.

Enqueues a new event for processing and waits until the event gets processed or until the timeout lapses.

Returns a Seqy.Event struct.

Link to this section Functions

@spec enqueue(event :: Seqy.Event.t()) :: :ok

Enqueues a new event for processing.

Link to this function

enqueue_await(event, timeout_in_ms \\ 5000)

View Source
@spec enqueue_await(Seqy.Event.t(), timeout_in_ms :: pos_integer()) ::
  term() | {:error, :timeout}

Enqueues a new event for processing and waits until the event gets processed or until the timeout lapses.

@spec new(params :: map()) :: Seqy.Event.t()

Returns a Seqy.Event struct.