Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Getting an Overview of Actors in an Akka System

DZone's Guide to

Getting an Overview of Actors in an Akka System

· Java Zone
Free Resource

What every Java engineer should know about microservices: Reactive Microservices Architecture.  Brought to you in partnership with Lightbend.

I've been playing around with akka-http and akka-streams lately and was wondering which kinds of actors were created when I create flow graphs and process http requests. I ran into the typesafe console, but that is already end of live (https://groups.google.com/forum/#!forum/typesafe-console) and doesn't support the newer versions of akka.

So after some looking around I ran into a post on stackoverflow providing an alternative approach (http://stackoverflow.com/questions/25860939/how-print-all-actors-in-akka...):

listactors.png

This posts lists some pseudo code, which pointed me in pretty much the right direction. I currently use the following actor to print out all the actors in the system:

class IDActor extends Actor with ActorLogging {
 
 def receive = {
    case "start" =>
      log.info("Current Actors in system:")
      self ! ActorPath.fromString("akka://Streams/user/")
 
    case path: ActorPath =>
      context.actorSelection(path / "*") ! Identify(())
 
    case ActorIdentity(_, Some(ref)) =>
      log.info(ref.toString())
      self ! ref.path
  }
}

To start this all we have to do is get the actor and message "start":

val idActor = system.actorOf(Props[IDActor],"idActor"); idActor ! "start"

The result is very interesting. For instance in a http-akka system with a couple of flows running I get the following overview of actors:

Current Actors in system:
Actor[akka://Streams/user/$a/flow-1-2-1-foreach-stageFactory#-1147809628]
Actor[akka://Streams/user/$a/flow-1-2-1-foreach-stageFactory#-1147809628]
Actor[akka://Streams/user/$a/flow-1-2-1-foreach-stageFactory#-1147809628]
Actor[akka://Streams/user/$a/flow-1-2-1-foreach-stageFactory#-1147809628]
Actor[akka://Streams/user/$a/flow-1-2-1-foreach-stageFactory#-1147809628]
Actor[akka://Streams/user/$a#-992619289]
Actor[akka://Streams/user/idActor#830993582]
Actor[akka://Streams/user/$a/flow-1-1-map#310662784]
...
Actor[akka://Streams/user/$a/flow-751-1-prefixAndTail#801612770]
Actor[akka://Streams/user/$a/flow-752-1-prefixAndTail#-1939947471]
Actor[akka://Streams/user/$a/flow-753-1-prefixAndTail#102076528]
Actor[akka://Streams/user/$a/flow-754-1-prefixAndTail#-1858318406]
Actor[akka://Streams/user/$a/flow-755-1-prefixAndTail#595550267]
Actor[akka://Streams/user/$a/flow-756-1-prefixAndTail#-1675014490]
Actor[akka://Streams/user/$a/flow-76-1-map#-1734873421]
Actor[akka://Streams/user/$a/flow-93-1-map#174954170]
Actor[akka://Streams/user/$a/flow-726-1-mapAsync#2041440238]
Actor[akka://Streams/user/$a/flow-725-1-mapAsync#-674218071]
Actor[akka://Streams/user/$a/flow-745-1-mapAsync#-800760294]

Cool right. Not that you can do much with it, but it at least gives you a good overview of what is happening internally.

Microservices for Java, explained. Revitalize your legacy systems (and your career) with Reactive Microservices Architecture, a free O'Reilly book. Brought to you in partnership with Lightbend.

Topics:

Published at DZone with permission of Jos Dirksen, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}