Over a million developers have joined DZone.

Getting an Overview of Actors in an Akka System

· Java Zone

Microservices! They are everywhere, or at least, the term is. When should you use a microservice architecture? What factors should be considered when making that decision? Do the benefits outweigh the costs? Why is everyone so excited about them, anyway?  Brought to you in partnership with IBM.

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.

Discover how the Watson team is further developing SDKs in Java, Node.js, Python, iOS, and Android to access these services and make programming easy. Brought to you in partnership with IBM.

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 best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

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

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

{{ parent.tldr }}

{{ parent.urlSource.name }}