I need to publish messages of different types to the event stream, and those messages must have different priorities, for example, if 10 messages of type A were published, and one message of type B was finally published, and priority B is higher than priority A - message B should be selected the next player, even if there are 10 messages in type A.
I read about priority messages here and created my simple implementation of this mailbox:
class PrioritizedMailbox(settings: Settings, cfg: Config) extends UnboundedPriorityMailbox(
PriorityGenerator {
case ServerPermanentlyDead => println("Priority:0"); 0
case ServerDead => println("Priority:1"); 1
case _ => println("Default priority"); 10
}
)
then I configured it in application.conf
akka {
actor {
prio-dispatcher {
type = "Dispatcher"
mailbox-type = "mailbox.PrioritizedMailbox"
}
}
}
and connected to my actor:
private val myActor = actors.actorOf(
Props[MyEventHandler[T]].
withRouter(RoundRobinRouter(HIVE)).
withDispatcher("akka.actor.prio-dispatcher").
withCreator(
new Creator[Actor] {
def create() = new MyEventHandler(storage)
}), name = "eventHandler")
I use ActorSystem.eventStream.publish to send messages, and my actor (I can see in the logs that the messages are being processed, but in FIFO).
, , logs/console
"Default priority". - ?
?
eventStream?