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
ack(id)
Acknowledges a dequeued message.
If the message is in-flight, it will not be re-added to the queue
after the alotted ttf.
Parameters
| name | description |
|---|---|
id | The id of the message to acknowledge (required). |
delete(queue, id)
Deletes a message by id.
Directly deletes a message in the queue.
Parameters
| name | description |
|---|---|
queue | The module type (atom) of the message to delete (required). |
id | The id of the message to delete (required). |
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
| name | description |
|---|---|
queue | The module type (atom) of the messages to delete (required). |
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
| name | description |
|---|---|
queue | The module type (atom) of the message to dequeue (required). |
ttf | The 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
| name | description |
|---|---|
message | The model instance to queue (required). |
get(queue, id)
Retrieves a message by id without dequeuing.
Recalling a message directly does NOT put it in flight.
Parameters
| name | description |
|---|---|
queue | The module type (atom) of the message to retrieve (required). |
id | The id of the message to retrieve (required). |
Initialises the Queues.
Example:
Enki.init([MyModel, MyOtherModel])
Parameters
| name | description |
|---|---|
types | A list of model instances to use as queue types (required). |
start(type, args)
Enki application start method.
Gets called automatically when included in your mix
applications list.