首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >scala 2.10,akka-camel tcp套接字通信

scala 2.10,akka-camel tcp套接字通信
EN

Stack Overflow用户
提问于 2013-01-23 16:10:12
回答 2查看 1.1K关注 0票数 2

我正在寻找一些简单和简短的例子,如何连接和进行交互(两种方式)与tcp套接字。换句话说,如何编写Scala2.10应用程序(使用akka-camel或netty库)来与tcp进程(套接字)通信。

我在互联网上发现了大量的文献,但是所有的东西都是旧的(寻找Scala2.10)和/或反对。

提前感谢!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-01-26 11:36:35

嗯,我在找这样的东西:

1.服务器:

代码语言:javascript
复制
import akka.actor._
import akka.camel.{ Consumer, CamelMessage }

class Ser extends Consumer {
  def endpointUri = "mina2:tcp://localhost:9002"
  def receive = {
    case message: CamelMessage => {
     //log
     println("looging, question:" + message)
     sender ! "server response to request: " + message.bodyAs[String] + ", is NO"
     }
   case _ => println("I got something else!??!!")
  }
}

object server extends App {

val system = ActorSystem("some")
val spust = system.actorOf(Props[Ser])
}

2. Client:

代码语言:javascript
复制
 import akka.actor._
 import akka.camel._
 import akka.pattern.ask
 import scala.concurrent.duration._
 import akka.util.Timeout
 import scala.concurrent.Await

 class Producer1 extends Actor with Producer {
   def endpointUri = "mina2:tcp://localhost:9002"
  }

 object Client extends App {

 implicit val timeout = Timeout(10 seconds)
 val system2 = ActorSystem("some-system")
 val producer = system2.actorOf(Props[Producer1])
 val future = producer.ask("Hello, can I go to cinema?")

 val result = Await.result(future, timeout.duration)
 println("Is future over?="+future.isCompleted+";;result="+result)

 println("Ende!!!")
 system2.shutdown
 println("system2 ended:"+system2.isTerminated)

我知道这是用http://doc.akka.io/docs/akka/2.1.0/scala/camel.html写的和描述得很好的一切。但是,如果您是新手,您需要全部阅读几遍才能构建非常简单的客户机-服务器应用程序。我认为某种“激励榜样”将是非常受欢迎的。

票数 2
EN

Stack Overflow用户

发布于 2013-01-24 08:06:55

我想你已经查过Akka文档了吗?http://doc.akka.io/docs/akka/2.1.0/scala/camel.html

在Akka 2.1.0中,他们改进了akka-骆驼模块,使其完全更新(以前有点过时)。

还有一个骆驼-阿克卡视频演示,涵盖了一个真实的用例:http://www.davsclaus.com/2012/04/great-akka-and-camel-presentation-video.html

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14484096

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档