title: Akka :: Using messages with different priorities over event stream in ActorSystem
body: <p>I need to publish messages of different types to  event stream, and those
  messages should have different priorities for example, if 10 messages of type
  A have been posted, and one message of type B is posted after all, and
  priority of B is higher than the priority of A - message B should be picked up
  by next actor even if there are 10 messages of type A in queue.</p>
  
  <p>I have read about prioritized messages <a href="http://doc.akka.io/docs/akka/2.0.3/scala/dispatchers.html#Mailboxes" rel="noreferrer">here</a> and created my simple implementation of that mailbox:</p>
  
  <pre><code>  class PrioritizedMailbox(settings: Settings, cfg: Config) extends UnboundedPriorityMailbox(
  
      PriorityGenerator {
        case ServerPermanentlyDead =&gt; println("Priority:0"); 0
        case ServerDead =&gt; println("Priority:1"); 1
        case _ =&gt; println("Default priority"); 10
      }
  
    )
  </code></pre>
  
  <p>then I configured it in application.conf</p>
  
  <pre><code>akka {
  
      actor {
  
          prio-dispatcher {
              type = "Dispatcher"
              mailbox-type = "mailbox.PrioritizedMailbox"
          }
  
      }
  
  }
  </code></pre>
  
  <p>and wired into my actor:</p>
  
  <pre><code>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")
  </code></pre>
  
  <p>I'm using ActorSystem.eventStream.publish in order to send messages, and my actor
  is subscribed to it (I can see in logs that messages are processed, but in
  FIFO order).</p>
  
  <p>However looks like it is not enough, because in logs/console I've never seen the
  messages like "Default priority". Am I missing something here? Does the
  described approach work with event streams or just with direct invocations of
  sending a message on actor? And how do I get prioritized messages with
  eventStream? </p>