Last active
March 31, 2016 07:25
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
At line #3 REPL throws:
com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'akka'