akka 简单例子总是 not delivered和dead letters encountered
package spark;
import akka.actor.{ Actor, Props, ActorSystem, ExtendedActorSystem }
import com.typesafe.config.ConfigFactory
import akka.remote._

object MyApp extends App {
  val actorSystem1 = ActorSystem("actorSystem1", ConfigFactory.parseString("""
    akka {
      remote {
        enabled-transports = ["akka.remote.netty.tcp"]
        netty.tcp {
          hostname = "127.0.0.1"
          port = 5155
        }
       }
    }
   """))
  val actorSystem2 = ActorSystem("actorSystem2")

  actorSystem1.actorOf(Props(new Actor {
    def receive = {
      case x: String =>
        Thread.sleep(1000)
        println("RECEIVED MESSAGE: " + x)
    }
  }), "simplisticActor")

  val remoteActor = actorSystem2.actorSelection("akka.tcp://actorSystem1@localhost:" + 5155 + "/user/simplisticActor")

  remoteActor ! "TEST 1"
  remoteActor ! "TEST 2"
  remoteActor ! "TEST 2"

  Thread.sleep(1000)

  actorSystem1.shutdown()
  actorSystem2.shutdown()
} 

1个回答

立即提问
相关内容推荐