Search code examples
scalaakkaactor

Cleaning of all messages from Akka Actor MailBox (Scala)


Are there ways to clean all messages from mailbox of actor? Actually, i need to do it with some frequency (for example 1 sec). If yes -> What is the easiest way to do this?


Solution

  • A possible approach would be to write your own mailbox. In this way you can keep the actual logic separated from this policy and it can become easier to configure and reuse the mailbox behavior.

    You can read more on how write your own mailbox here.

    Once you have implemented your own mailbox you can specify it with the withMailbox method when you instantiate the actor Props to create the actor.