itk_queue v0.10.14 ITKQueue View Source

Provides convenience functions for subscribing to queues and publishing messages.

Link to this section Summary

Functions

Deletes a queue

Publish a message. Expects the message to be something that can be encoded as JSON

Link to this section Types

Link to this type message() View Source
message() :: %{optional(String.t()) => any()}
Link to this type metadata() View Source
metadata() :: %{optional(atom()) => any()}

Link to this section Functions

Link to this function declare_queue(queue_name, options \\ []) View Source
declare_queue(queue_name :: String.t(), options :: Keyword.t()) ::
  :ok | no_return()

Declares a queue.

Link to this function delete_queue(queue_name) View Source
delete_queue(queue_name :: String.t()) :: :ok | no_return()

Deletes a queue.

Link to this function publish(routing_key, message, options \\ []) View Source
publish(routing_key :: String.t(), message :: map(), options :: Keyword.t()) ::
  :ok

Publish a message. Expects the message to be something that can be encoded as JSON.

Examples

iex> ITKQueue.publish("data.sync", %{type: "user", data: %{name: "Test User"}})
Link to this function subscribe(queue_name, routing_key, handler) View Source
subscribe(
  queue_name :: String.t(),
  routing_key :: String.t(),
  handler :: (any() -> any())
) :: {:ok, pid()}
subscribe(
  queue_name :: String.t(),
  routing_key :: String.t(),
  handler :: (any(), any() -> any())
) :: {:ok, pid()}

Subscribes to a queue.

The handler is expected to be a function that handles the message. If the function raises an exception the message will be moved to a temporary queue and retried after a delay.

Examples

iex> ITKQueue.subscribe("students-data-sync", "data.sync", fn(message) -> IO.puts(inspect(message)) end)