These are chat archives for petabridge/akka-bootcamp

Aug 2015
Michael Dadashyan
Aug 26 2015 02:04
Hello, i have a system that pulls some data from 3rd party API. One api method contains basic record that I save into local db (insert new records if not exist yet). The other method provides some additional data for the same records (update records by Id and never insert new records). Each call can result in several hundreds or even thousands of records and sometimes the messages come out of order i.e. I can get the update before I processed the insert so I am not able to find a record to update. What is the best way to retry the same message later? Should I throw an exception and make the supervisor to handle it? Or maybe I can just do Self.Tell(updateMessage);?
Roger Johansson
Aug 26 2015 05:49
It depends how fast the insert message arrives, eg lets say you only have the update message and you send it to self, and the insert doesnt arrive for 5 min, then you will burn a lot of CPU processing that update message over and over thousands of times per sec
You could use scheduler.tellonce(delay, message, self)
That will resend the update message in x time
Or, you can add it to a list of "unprocessed messages" inside your actor, and each time you receive a message, you try to process the messages in that list
And remove the ones that could be processed
That is probably the best way, that would work with akka persistence too
Michael Dadashyan
Aug 26 2015 22:56
@rogeralsing Thanks for the answer - I want to clarify a bit my situation. The insert message most probably already arrived and just sitting in the mailbox of the exact same actor or one of the siblings in the same routing pool. What I want to do, is simply put the unprocessed message to the end of the mailbox. Probably the beter way would be to stash and unstash it instead of Tell() to Self? What do you think?