akka-persistence vs durable mailbox

1,499 views
Skip to first unread message

Logan Aube

unread,
Mar 24, 2014, 10:03:25 AM3/24/14
to akka...@googlegroups.com
Hello,

I was looking to use durable mailboxes in a new akka project. Looking through the documentation, it appears these have been dropped in favour of akka-persistence.

I took a look into the akka-persistence documentation and from what I can gather the goal of the project is to store processed messages so that an actor's state can be rebuilt upon an actor's restart, while I'd like to store unprocessed messages so they can be processed upon an actor's restart (for my purposes, my actor is essentially stateless).

Am I understanding this incorrectly? Is there a way to accomplish my goal with the persistence module, or is there an alternative approach?

Thanks!

Akka Team

unread,
Mar 24, 2014, 10:22:44 AM3/24/14
to Akka User List
Hi Logan,


I took a look into the akka-persistence documentation and from what I can gather the goal of the project is to store processed messages so that an actor's state can be rebuilt upon an actor's restart, while I'd like to store unprocessed messages so they can be processed upon an actor's restart (for my purposes, my actor is essentially stateless).

Processors (http://doc.akka.io/docs/akka/2.3.0/scala/persistence.html#Processors) store the message *first* and then process them. If you do not want to keep the whole history of the Processor in the journal you can delete messages: http://doc.akka.io/docs/akka/2.3.0/scala/persistence.html#Message_deletion

-Endre
 

Am I understanding this incorrectly? Is there a way to accomplish my goal with the persistence module, or is there an alternative approach?

Thanks!

--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.



--
Akka Team
Typesafe - The software stack for applications that scale
Blog: letitcrash.com
Twitter: @akkateam

Patrik Nordwall

unread,
Mar 24, 2014, 10:53:23 AM3/24/14
to akka...@googlegroups.com
The big difference is that when using akka-persistence the messages are not stored immediately when placed in the mailbox. When you receive the Persistent message in the Processor you know that it has been stored. The sender can let go of the responsibility when it has received an explicit acknowledgement message from the Processor.

A safe hand-off like that can also be implemented with a PersistentChannel. This is rather close to a durable mailbox, but so much better.

class Endpoint extends Actor {
  val channel = context.actorOf(PersistentChannel.props(
    PersistentChannelSettings(redeliverInterval = 3.seconds, redeliverMax = 10,
      replyPersistent = true)), name = "myChannel")
  val destination = context.system / "jobManager"

  import context.dispatcher
  implicit val timeout = Timeout(5.seconds)
 

  def receive = {
    case job: Job =>
      (channel ? Deliver(Persistent(job), destination)) map {
        case _: Persistent => "OK: " + job.id
      } recover {
        case e => "FAILED: " + job.id
      } pipeTo sender()
  }
}

Cheers,
Patrik

Patrik Nordwall
Typesafe Reactive apps on the JVM
Twitter: @patriknw

Logan Aube

unread,
Mar 24, 2014, 11:17:00 AM3/24/14
to akka...@googlegroups.com
Great, thanks guys for pointing me in the right direction!

Jeff Simpson

unread,
Jul 8, 2014, 5:38:56 PM7/8/14
to akka...@googlegroups.com
The main difference I see with the change from a DurableMailbox to using a PersistentChannel/AtLeastOnceDelivery is the former seems "pull" based while the latter is "push". Is this the case? I'm curious if there's a way I can essentially implement a durable mailbox based on the Persistence framework?  Basically I want to pile a bunch of messages into this mailbox and have the actor process them when it "can" with a producer timeout restriction. I know this is related to the Reactive Stream stuff, but I'm interested in something near term and deciding if I should implement a DurableMailbox or spend more time trying to bend Persistence to work with my stateless actor.

Thanks
-Jeff

Konrad Malawski

unread,
Jul 14, 2014, 6:09:36 AM7/14/14
to Akka User List

Hello Jeff,

Basically I want to pile a bunch of messages into this mailbox and have the actor process them when it "can" with a producer timeout restriction. I know this is related to the Reactive Stream stuff, but I'm interested in something near term and deciding if I should implement a DurableMailbox or spend more time trying to bend Persistence to work with my stateless actor.

When reading your description I was about to answer “reactive streams”, but I see you’re well aware already :-)

Have you seen this thread: [akka-user] Pulling pattern vs. Durable Mailboxes?

One thing you could do is to introduce an intermediate actor, which will handle the persisting, and your worker actor would pull the work from this PersistentActor.
The persistentActor can then deleteMessages(toSequenceNr: Long) once it gets a confirmation that the worker processed messages until N.

--
Cheers,
Konrad 'ktoso' Malawski
hAkker @ Typesafe


Reply all
Reply to author
Forward
0 new messages