enki v0.2.0 Enki

Enki is a simple queue that provides Mnesia persistence across nodes and ttf (time-to-flight) capability.

Time-to-flight means that, when dequeuing a message, if the dequeue is not ack'd within a given period of time, the message is automatically added back to the queue. This ensures that no messages are lost.

Queues must be created by calling Enki.init and passing a list of model module names. Each model must be created as

defmodule MyApp.MyModel do
  use Enki.Message,
    attributes: [:attr1, :attr2, :attr3]
end

This replaces the need to use defstruct, as it ensures the correct Enki meta is used.

Examples

Enki.init([MyModel])
Enki.enq(%MyModel{a: 1, b: 2})
%MyModel{enki_id: id, a: 1, b: 2}} = Enki.deq(MyModel)
:ok = Enki.ack(id)

Link to this section Summary

Functions

Acknowledges a dequeued message.

Deletes a message by id.

Delete all messages in the queue.

Dequeues a message from the queue.

Adds a message to the queue.

Retrieves a message by id without dequeuing.

Initialises the Queues.

Enki application start method.

Link to this section Functions

Acknowledges a dequeued message.

If the message is in-flight, it will not be re-added to the queue after the alotted ttf.

Parameters

namedescription
idThe id of the message to acknowledge (required).
Link to this function

delete(queue, id)

Deletes a message by id.

Directly deletes a message in the queue.

Parameters

namedescription
queueThe module type (atom) of the message to delete (required).
idThe id of the message to delete (required).
Link to this function

delete_all(queue)

Delete all messages in the queue.

Any in-flight messages are cancelled, so messages are not added back to the queue.

Parameters

namedescription
queueThe module type (atom) of the messages to delete (required).
Link to this function

deq(queue, ttf \\ nil)

Dequeues a message from the queue.

Returns the message in a Message model as its payload parameter. The message is typically the oldest in the queue.

Parameters

namedescription
queueThe module type (atom) of the message to dequeue (required).
ttfThe time-to-flight for the message. If provided, verrides the message in the config (optional).

Adds a message to the queue.

Returns a Message instance containing the enki_id of the message on the queue and the message itself as a payload.

Parameters

namedescription
messageThe model instance to queue (required).

Retrieves a message by id without dequeuing.

Recalling a message directly does NOT put it in flight.

Parameters

namedescription
queueThe module type (atom) of the message to retrieve (required).
idThe id of the message to retrieve (required).
Link to this function

init(types)

init([atom()]) :: :ok | no_return()

Initialises the Queues.

Example:

Enki.init([MyModel, MyOtherModel])

Parameters

namedescription
typesA list of model instances to use as queue types (required).
Link to this function

start(type, args)

Enki application start method.

Gets called automatically when included in your mix applications list.