2011-12-12 08:37:18 +01:00
|
|
|
|
|
|
|
|
.. _durable-mailboxes:
|
|
|
|
|
|
|
|
|
|
###################
|
|
|
|
|
Durable Mailboxes
|
|
|
|
|
###################
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Overview
|
|
|
|
|
========
|
|
|
|
|
|
|
|
|
|
Akka supports a set of durable mailboxes. A durable mailbox is a replacement for
|
|
|
|
|
the standard actor mailbox that is durable. What this means in practice is that
|
|
|
|
|
if there are pending messages in the actor's mailbox when the node of the actor
|
|
|
|
|
resides on crashes, then when you restart the node, the actor will be able to
|
|
|
|
|
continue processing as if nothing had happened; with all pending messages still
|
|
|
|
|
in its mailbox.
|
|
|
|
|
|
2011-12-15 14:26:17 +01:00
|
|
|
None of these mailboxes implements transactions for current message. It's possible
|
2011-12-12 08:37:18 +01:00
|
|
|
if the actor crashes after receiving a message, but before completing processing of
|
2011-12-15 14:26:17 +01:00
|
|
|
it, that the message could be lost.
|
2011-12-12 08:37:18 +01:00
|
|
|
|
|
|
|
|
.. warning:: **IMPORTANT**
|
|
|
|
|
|
2011-12-15 14:26:17 +01:00
|
|
|
None of these mailboxes work with blocking message send, i.e. the message
|
2011-12-12 08:37:18 +01:00
|
|
|
send operations that are relying on futures; ``?`` or ``ask``. If the node
|
|
|
|
|
has crashed and then restarted, the thread that was blocked waiting for the
|
|
|
|
|
reply is gone and there is no way we can deliver the message.
|
|
|
|
|
|
2012-05-08 16:16:47 +02:00
|
|
|
The durable mailboxes supported out-of-the-box are:
|
2011-12-12 08:37:18 +01:00
|
|
|
|
|
|
|
|
- ``FileBasedMailbox`` -- backed by a journaling transaction log on the local file system
|
|
|
|
|
|
2012-05-08 16:16:47 +02:00
|
|
|
You can easily implement your own mailbox. Look at the existing implementation for inspiration.
|
2011-12-12 08:37:18 +01:00
|
|
|
|
|
|
|
|
.. _DurableMailbox.General:
|
|
|
|
|
|
|
|
|
|
General Usage
|
|
|
|
|
-------------
|
|
|
|
|
|
|
|
|
|
The durable mailboxes and their configuration options reside in the
|
|
|
|
|
``akka.actor.mailbox`` package.
|
|
|
|
|
|
|
|
|
|
You configure durable mailboxes through the dispatcher. The
|
2011-12-15 14:26:17 +01:00
|
|
|
actor is oblivious to which type of mailbox it is using.
|
2011-12-19 20:36:06 +01:00
|
|
|
|
|
|
|
|
In the configuration of the dispatcher you specify the fully qualified class name
|
|
|
|
|
of the mailbox:
|
|
|
|
|
|
|
|
|
|
.. includecode:: code/akka/docs/actor/mailbox/DurableMailboxDocSpec.scala
|
|
|
|
|
:include: dispatcher-config
|
|
|
|
|
|
|
|
|
|
Here is an example of how to create an actor with a durable dispatcher, in Scala:
|
2011-12-12 08:37:18 +01:00
|
|
|
|
|
|
|
|
.. includecode:: code/akka/docs/actor/mailbox/DurableMailboxDocSpec.scala
|
2011-12-19 20:36:06 +01:00
|
|
|
:include: imports,dispatcher-config-use
|
2011-12-12 08:37:18 +01:00
|
|
|
|
|
|
|
|
Corresponding example in Java:
|
|
|
|
|
|
|
|
|
|
.. includecode:: code/akka/docs/actor/mailbox/DurableMailboxDocTestBase.java
|
2011-12-19 20:36:06 +01:00
|
|
|
:include: imports,dispatcher-config-use
|
2011-12-12 08:37:18 +01:00
|
|
|
|
|
|
|
|
The actor is oblivious to which type of mailbox it is using.
|
|
|
|
|
|
|
|
|
|
This gives you an excellent way of creating bulkheads in your application, where
|
|
|
|
|
groups of actors sharing the same dispatcher also share the same backing
|
|
|
|
|
storage. Read more about that in the :ref:`dispatchers-scala` documentation.
|
|
|
|
|
|
|
|
|
|
File-based durable mailbox
|
|
|
|
|
==========================
|
|
|
|
|
|
|
|
|
|
This mailbox is backed by a journaling transaction log on the local file
|
|
|
|
|
system. It is the simplest to use since it does not require an extra
|
|
|
|
|
infrastructure piece to administer, but it is usually sufficient and just what
|
|
|
|
|
you need.
|
|
|
|
|
|
|
|
|
|
You configure durable mailboxes through the dispatcher, as described in
|
|
|
|
|
:ref:`DurableMailbox.General` with the following mailbox type.
|
|
|
|
|
|
2011-12-19 20:36:06 +01:00
|
|
|
Config::
|
2011-12-12 08:37:18 +01:00
|
|
|
|
2011-12-19 20:36:06 +01:00
|
|
|
my-dispatcher {
|
2012-02-09 20:40:09 +01:00
|
|
|
mailbox-type = akka.actor.mailbox.FileBasedMailboxType
|
2011-12-19 20:36:06 +01:00
|
|
|
}
|
2011-12-12 08:37:18 +01:00
|
|
|
|
|
|
|
|
You can also configure and tune the file-based durable mailbox. This is done in
|
|
|
|
|
the ``akka.actor.mailbox.file-based`` section in the :ref:`configuration`.
|
|
|
|
|
|
|
|
|
|
.. literalinclude:: ../../akka-durable-mailboxes/akka-file-mailbox/src/main/resources/reference.conf
|
|
|
|
|
:language: none
|
|
|
|
|
|