akka zeromq - 订阅者不接收消息

时间:2014-11-20 21:35:50

标签: akka zeromq subscriber

我正在使用scala中的akka​​ zeromq编写这个简单的hello -world有点玩具程序。我的订阅者似乎没有收到任何消息。我看到发布者从发布者的接收方法发布的消息,但就是这样。任何人都可以帮助我让这个程序工作!

提前谢谢你。

import akka.util.ByteString
import akka.zeromq._
import akka.actor._
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits.global


class Sub extends Actor{
  def receive  = {
    //case m:ZMQMessage if m.frames(0).utf8String == "hello" => println(m.frames(1).toString())
    case m:ZMQMessage => println("************* from subscriber *****************") //;println(m.frames(1).toString())
    case ss :String => println (" ---- some string appeared ")
    //case _ =>
  }
}


class Pub extends Actor{

  //creates a publisher socket bound to host at port 1235
  val pubSocket = ZeroMQExtension(context.system).newSocket(SocketType.Pub, Bind("tcp://*:1235"))

  def receive={
    case msg:String =>
      println(s"Got Message $msg")
      pubSocket ! ZMQMessage(ByteString("hello"), ByteString("this is test message"))
  }
}

object main extends App {

  println("Starting App.")

  val system = ActorSystem("system")

  val subActor = system.actorOf(Props[Sub])
  val pubActor = system.actorOf(Props[Pub])

  // sockets are created using ZeroMQExtension
  // creates a subscriber socket
  val subSocket = ZeroMQExtension(system).newSocket(SocketType.Sub, Listener(subActor), Connect("tcp://*:1235"), SubscribeAll)

  system.scheduler.schedule(1 seconds, 0 minutes)(pubActor ! "Message to Pub")

  println("Exiting main.")
}

0 个答案:

没有答案