Simple Scala Akka Actor examples (Hello, world examples) | alvinalexander.com
Scala Actors FAQ: Can you share a Scala Akka Actors example/tutorial? Sure. Most of the Scala Akka Actor tutorials I see jump right into the deep end, throwing you into some tough concepts right away. Personally I'm more into the "crawl before you walk approach", and to that end, here are some simple Akka Actor examples, of the "Hello, world" variety. A simple Akka "Hello, world" example My first Akka Actor example is about as simple as I can make it: import akka.actor.Actor import akka.actor.ActorSystem import akka.actor.Props class HelloActor extends Actor { def receive = { case "hello" => println("hello back at you") case _ => println("huh?") } } object Main extends App { val system = ActorSystem("HelloSystem") // default Actor constructor val helloActor = system.actorOf(Props[HelloActor], name = "helloactor") helloActor ! "hello" helloActor ! "buenos dias" } Here's a quick description of this example: Import all the Akka actor classes you need. Define an Actor,Read full article from Simple Scala Akka Actor examples (Hello, world examples) | alvinalexander.com
No comments:
Post a Comment