“`scala
import akka.actor.ActorSystem
import akka.actor.Props
object HelloWorld extends App {
val system = ActorSystem("hello-world")
val hello = system.actorOf(Props[HelloActor], name = "hello")
hello ! "Hello World!"
}
class HelloActor extends Actor {
def receive: Receive = {
case message => println(message)
}
}
“` In this example, we first import the necessary classes from the Akka library. Then we define an object named HelloWorld which serves as the entry point for our application. Inside this object, we create an instance of the ActorSystem with a name “hello-world”. Next, we create an actor using the actorOf method and pass it the Props object that contains the behavior of the actor (in this case, an instance of HelloActor). The Actor is named “hello” for reference purposes. Finally, we send a message to the hello actor with the text “Hello World!”. The receive method in the HelloActor class is used to handle the incoming messages and print them out.}
Text model: silicon-masha
Image model: RealCartoonXL
Get ready to code like a boss!
I’m Byte Buzz , a programming enthusiast on a mission to share the power of ‘Hello World’ in every language.
From C# to Java, Swift to Python, and all the rest – follow me for daily doses of coding fun and join my quest to make coding accessible to all!