akka 2.3.11 实例

来源:互联网 发布:仿真优化软件 编辑:程序博客网 时间:2024/05/18 01:53
package test;import akka.actor.{ Actor, Props, ActorSystem, ExtendedActorSystem }import com.typesafe.config.ConfigFactoryimport akka.remote._object MyApp extends App {  val actorSystem1 = ActorSystem("actorSystem1", ConfigFactory.parseString("""    akka {     actor {        provider = "akka.remote.RemoteActorRefProvider"      }      remote {        netty.tcp {          hostname = "127.0.0.1"          port = "2555"        }      }    }   """))  val provider = actorSystem1.asInstanceOf[ExtendedActorSystem].provider  val boundPort = provider.getDefaultAddress.port.get  System.out.println(boundPort + "!!!")  val actorSystem2 = ActorSystem("actorSystem2", ConfigFactory.parseString("""    akka {     actor {        provider = "akka.remote.RemoteActorRefProvider"      }      remote {        netty.tcp {          hostname = "127.0.0.1"          port = "2554"        }      }    }   """))  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@127.0.0.1:" + boundPort + "/user/simplisticActor")//127.0.0.1不能写成localhost  remoteActor ! "TEST 1"  remoteActor ! "TEST 2"  remoteActor ! "TEST 3"  Thread.sleep(5000)  actorSystem1.shutdown()  actorSystem2.shutdown()}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56

全部从官网同一个akka版本里的 
akka-actor_2.10-2.3.11.jar 
akka-remote_2.10-2.3.11.jar 
config-1.2.1.jar 
netty-3.8.0.Final.jar 
protobuf-java-2.5.0.jar


0 0
原创粉丝点击