There are some situations when you want an actor to process certain messages first and then other ones. So, I am going to demonstrate how to create a priority based mailbox for an actor.
Suppose we have an actor.
Now we want to process our messages in order like (string, Int , Long , other messages).
So what we need to do is to just write a priority based mailbox as below.
Here zero denotes highest priority.
After that add this configuration to application.conf.
At the time of actor creation specify the dispatcher class as below.
Suppose you send below messages to actor, in such a case string messages would be picked up first.
You can find the sample code here in github.
How to run the code.
After cloning the repo, go to the console and do sbt run in the project directory, it will show following output in console.
Note that using this type of mailbox does not preserve message ordering, which you get with the default mailbox queue. So mixing this with for example data streams using Akka IO leads to pretty funny results.
Roland Kuhn updated to stable priority inboxes in 2.4-M1 so we should see those released before too long. Woot!
https://github.com/akka/akka/commit/8df81e6b724fa527e97ae6e5b23515cd3f5fe17d#diff-ee52c1a2f4c5add3f88a59b37a245d31
Hi Adrien
Thanks for sharing your experience. I will look into this as well.
This is great, thanks!