itk_queue v0.9.4 ITKQueue

Provides convenience functions for subscribing to queues and publishing messages.

Summary

Functions

Deletes a queue

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

Types

message()
message() :: %{optional(String.t) => any}
metadata()
metadata() :: %{optional(atom) => any}

Functions

declare_queue(queue_name, options \\ [])
declare_queue(queue_name :: String.t, options :: Keyword.t) ::
  :ok |
  no_return

Declares a queue.

delete_queue(queue_name)
delete_queue(queue_name :: String.t) :: :ok | no_return

Deletes a queue.

publish(routing_key, message, options \\ [])
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"}})
subscribe(queue_name, routing_key, handler)
subscribe(queue_name :: String.t, routing_key :: String.t, handler :: (any, any -> any)) :: {:ok, pid}
subscribe(queue_name :: String.t, routing_key :: String.t, handler :: (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)