问题
我正在尝试实现一个简单的参与者,它将使用 akka-zeromq 从 zeromq 接收消息。
import akka.actor._
import akka.zeromq._
class PullActor extends Actor {
def receive = {
case x => println("M: " + x.toString)
}
}
object Main extends App {
val system = ActorSystem("system")
val pullActor = system.actorOf(Props[PullActor], "pull-actor")
val pullSocket = ZeroMQExtension(system).newSocket(
SocketType.Pull, Listener(pullActor), Connect("tcp://127.0.0.1:8008"))
println("Press ENTER to exit")
Console.readLine()
system.shutdown()
}
系统只打印
M: Connecting
附加信息
发送消息是通过一个简单的 python 完成的
import zmq
ctx = zmq.Context()
p = ctx.socket(zmq.PUSH)
p.bind("tcp://*:8008")
p.send("test")
我注意到的另一件奇怪的事情是,在按下 enter 后,程序不会终止。如果我使用 python 脚本向它发送消息,它会。这是完整的输出:
[DEBUG] [12/04/2012 18:01:45.175] [main] [EventStream(akka://system)] logger log1-Logging$DefaultLogger started
[DEBUG] [12/04/2012 18:01:45.178] [main] [EventStream(akka://system)] Default Loggers started
Press ENTER to exit
M: Connecting
[DEBUG] [12/04/2012 18:01:54.176] [system-akka.actor.default-dispatcher-2] [EventStream] shutting down: StandardOutLogger started
[DEBUG] [12/04/2012 18:01:54.176] [system-akka.actor.default-dispatcher-2] [EventStream] shutting down: StandardOutLogger started
[DEBUG] [12/04/2012 18:01:54.179] [system-akka.actor.default-dispatcher-2] [EventStream] all default loggers stopped
使用
scalaVersion := "2.10.0-RC3"
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor" % "2.1.0-RC3" cross CrossVersion.full,
"com.typesafe.akka" %% "akka-zeromq" % "2.1.0-RC3" cross CrossVersion.full,
"com.typesafe.akka" %% "akka-slf4j" % "2.1.0-RC3" cross CrossVersion.full
)
libzmq
是版本3.2.2
(在 Arch Linux 上)
这是application.conf
akka {
loglevel = DEBUG
zeromq {
socket-dispatcher {
executor = thread-pool-executor
type = "PinnedDispatcher"
}
}
}