itk_queue v0.5.4 ITKQueue

Provides convenience functions for subscribing to queues and publishing messages.

Summary

Functions

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

Functions

publish(routing_key, message)
publish(routing_key :: String.t, message :: Map.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)) :: {:ok, pid}
subscribe(queue_name :: String.t, routing_key :: String.t, handler :: (... -> 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)