注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

阿弥陀佛

街树飘影未见尘 潭月潜水了无声 般若观照心空静...

 
 
 

日志

 
 
关于我

一直从事气象预报、服务建模实践应用。 注重气象物理场、实况场、地理信息、本体知识库、分布式气象内容管理系统建立。 对Barnes客观分析, 小波,计算神经网络、信任传播、贝叶斯推理、专家系统、网络本体语言有一定体会。 一直使用Java、Delphi、Prolog、SQL编程。

网易考拉推荐

akka client/server程序测试  

2014-09-10 15:24:19|  分类: Akka |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

第一步,建立远程backend server
F:\>cd akka-in-action\chapter6

F:\akka-in-action\chapter6>sbt console
[info] Loading project definition from F:\akka-in-action\chapter6\project
[info] Set current project to goticks (in build file:/F:/akka-in-action/chapter6
/)
[info] Starting scala interpreter...
[info]
Welcome to Scala version 2.11.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_5
1).
Type in expressions to have them evaluated.
Type :help for more information.

scala> :paste
// Entering paste mode (ctrl-D to finish)
val conf = """
akka {
    actor {
        provider = "akka.remote.RemoteActorRefProvider"
    }
    remote {
       enabled-transports = ["akka.remote.netty.tcp"]
       netty.tcp {
           hostname = "0.0.0.0"
           port = 2551
        }
    }
}
"""
// Exiting paste mode, now interpreting.
scala> import com.typesafe.config._
import com.typesafe.config._
scala> import akka.actor._
import akka.actor._
scala> val config = ConfigFactory.parseString(conf)
config: com.typesafe.config.Config = Config(SimpleConfigObject({"akka":{"actor":
{"provider":"akka.remote.RemoteActorRefProvider"},"remote":{"enabled-transports"
:["akka.remote.netty.tcp"],"netty":{"tcp":{"hostname":"0.0.0.0","port":2551}}}}}
))

scala> val backend = ActorSystem("backend", config)
[INFO] [09/10/2014 11:39:15.286] [run-main-0] [Remoting] Starting remoting
[INFO] [09/10/2014 11:39:15.540] [run-main-0] [Remoting] Remoting started; liste
ning on addresses :[akka.tcp://backend@0.0.0.0:2551]
[INFO] [09/10/2014 11:39:15.543] [run-main-0] [Remoting] Remoting now listens on
 addresses: [akka.tcp://backend@0.0.0.0:2551]
backend: akka.actor.ActorSystem = akka://backend

scala>
The Remoting module now listens on all interfaces (0.0.0.0) on port 2551 for the backend actor system.
scala>:paste
class Simple extends Actor {
  def receive = {
    case m => println(s"received $m!")
  }
}
scala> backend.actorOf(Props[Simple], "simple")
res0: akka.actor.ActorRef = Actor[akka://backend/user/simple#-778735859]
======================================================================
第二步,建立frontend
F:\>cd akka-in-action\chapter6
scala> :paste
// Entering paste mode (ctrl-D to finish)
val conf = """
akka {
    actor {
        provider = "akka.remote.RemoteActorRefProvider"
    }
   remote {
      enabled-transports = ["akka.remote.netty.tcp"]
      netty.tcp {
          hostname = "0.0.0.0"
          port = 2552
       }
   }
}
"""

import com.typesafe.config._
import akka.actor._
val config = ConfigFactory.parseString(conf)
val frontend= ActorSystem("frontend", config)
scala> val frontend= ActorSystem("frontend", config)
[INFO] [09/10/2014 14:57:15.782] [run-main-0] [Remoting] Starting remoting
[INFO] [09/10/2014 14:57:15.956] [run-main-0] [Remoting] Remoting started; liste
ning on addresses :[akka.tcp://frontend@0.0.0.0:2552]
[INFO] [09/10/2014 14:57:15.958] [run-main-0] [Remoting] Remoting now listens on
 addresses: [akka.tcp://frontend@0.0.0.0:2552]
frontend: akka.actor.ActorSystem = akka://frontend
The frontendactorsystem is now also running and remoting has started.

scala> val path = "akka.tcp://backend@0.0.0.0:2551/user/simple"
path: String = akka.tcp://backend@0.0.0.0:2551/user/simple

scala> val simple = frontend.actorSelection(path)
simple: akka.actor.ActorSelection = ActorSelection[Anchor(akka.tcp://backend@0.0
.0.0:2551/), Path(/user/simple)]
Think of the ActorSelection method as a query in the actor hierarchy.
在frontend输入:
scala> simple ! "Hello 何险峰!"
在backend得到:
scala> received received Hello 何险峰!!
成功了哈,多了一个感叹号。
  评论这张
 
阅读(728)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017