Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // remote actor
- main.scala
- ----
- package com.fullfacing.ticketingworker
- import akka.actor.{Props, ActorSystem}
- import com.fullfacing.ticketingworker.actor.TicketActor
- import com.typesafe.config.ConfigFactory
- /**
- * Created by ryno on 2015/04/15.
- */
- object main {
- val name = "TicketHandlingSystem"
- val system = ActorSystem(name, ConfigFactory.load())
- def shutdown(): Unit = {
- system.shutdown()
- }
- def main(args: Array[String]) = {
- system.actorOf(Props[TicketActor], "TicketActor")
- sys.addShutdownHook { shutdown() }
- println("started TicketHandlingSystem")
- }
- }
- ---
- TicketActor.scala
- ---
- package com.fullfacing.ticketingworker.actor
- import akka.actor.Actor
- /**
- * Created by ryno on 2015/04/15.
- */
- class TicketActor extends Actor {
- override def receive: Receive = {
- case msg: String =>
- println(s"tickets: $msg have been booked.")
- sender() ! "done booking"
- }
- }
- ---
- application.conf
- ---
- akka {
- actor {
- provider = "akka.remote.RemoteActorRefProvider"
- }
- remote {
- enabled-transports = ["akka.remote.netty.tcp"]
- netty.tcp {
- hostname = "localhost"
- port = 5150
- }
- }
- }
- ------------------------------------------------
- local actor
- ------------------------------------------------
- main.scala
- ---
- package com.fullfacing.ticketing
- import akka.actor.{ActorSystem, Props}
- import com.fullfacing.ticketing.actor.{TestActor, ApiActor}
- import com.typesafe.config.ConfigFactory
- /**
- * Created by ryno on 2015/04/15.
- */
- object main {
- val name = "TicketHandlingSystem"
- val system = ActorSystem(name, ConfigFactory.load())
- def shutdown(): Unit = {
- system.shutdown()
- }
- def main(args: Array[String]) = {
- val actor = system.actorOf(Props[TestActor], "TicketActor")
- sys.addShutdownHook { shutdown() }
- println("started TicketHandlingSystem")
- Thread.sleep(1000)
- actor ! "moo moo cow"
- }
- }
- ---
- TestActor.scala
- ---
- package com.fullfacing.ticketing.actor
- import akka.actor._
- /**
- * Created by ryno on 2015/04/15.
- */
- class TestActor extends Actor {
- val handler = context.actorSelection("akka.tcp://TicketHandlingSystem@localhost:5150/user/TicketActor")
- handler ! Identify(None)
- override def receive: Receive = {
- case ActorIdentity(_, Some(actorRef)) =>
- println("identified")
- context become ready(actorRef)
- case ActorIdentity(_, None) => println("its not alive")// not alive
- }
- def ready(remote: ActorRef): Receive = {
- case m: String => remote ! m
- }
- }
- ---
- application.conf
- ---
- akka {
- loglevel = "DEBUG"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement