How to register all incoming messages from Akka (Java)

In Scala, you can wrap a receive function with LoggingReceive. How do you achieve the same from the Java API?

def receive = {
  LoggingReceive {
    case x ⇒ // do something
  }
}
+4
source share
1 answer

The Scala API has a decoder LoggingReceivebecause the partial function literal makes it inconvenient to express something that needs to be done in all cases (for example, this log).

In Java, you do not have this problem, because your method is onReceivealways called, and you can put the registration operator at the top to view all the messages received by the actor. As an added bonus, you decide at what level to register them :-)

akka.actor.debug.receive ( Scala), , ,

if (getContext().system().settings().AddLoggingReceive())
  log.debug("received message of type {}", msg.getClass());
+7

All Articles