Skip to content

Instantly share code, notes, and snippets.

@langley
Last active March 31, 2016 07:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save langley/8086211 to your computer and use it in GitHub Desktop.
Save langley/8086211 to your computer and use it in GitHub Desktop.
Use simple Akka actors from the REPL. I should probably also illustrate a simple sbt project that just depends on Akka to make starting a repl with akka easy
import akka.actor._
// need an actor system, make it implicit to it's used by all our repl based actors
implicit val system = ActorSystem("replActorSystem")
// this gives us an easy way to define simple actors
import ActorDSL._
// here's a simple example of creating an actor
// Also, this will give us a simple actor that is used to print the
// results sent back to us from the other actors.
implicit val sender = actor(new Act { become { case msg => println(msg) } } )
// Another actor to talk to
val anotherActor = actor(new Act { become { case msg => sender ! s"I heard you say: $msg" }})
// Now send the other actor something
anotherActor ! "a simple string message"
// And you'll see the below, shown in a comment so you can copy & paste all of this into your repl window
// scala> I heard you say: a simple string message
// Note you see the response because of our implicit sender defined above.
@IvanZelenskyy
Copy link

At line #3 REPL throws:
com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'akka'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment