I am writing this simple hello -world kinda toy program using akka zeromq in scala. It appears that my subscriber doesnt receive any messages. I see messages published by the publisher from receive method of publisher but that is it. Can anyone please help me with get this program working !
Thank you in advance.
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.")
}