Skip to content

Instantly share code, notes, and snippets.

@ANorwell
Created July 26, 2012 19:55
Show Gist options
  • Save ANorwell/3184152 to your computer and use it in GitHub Desktop.
Save ANorwell/3184152 to your computer and use it in GitHub Desktop.
ZMQ Push/Pull needs sleep
package com.test
import akka.actor._
import akka.zeromq._
class PullTestActor(val address: String) extends Actor {
val pullSocket = context.system.newSocket(SocketType.Pull,
Bind(address), Listener(self))
def receive = {
case m: ZMQMessage ⇒
val s = new String(m.payload(0))
println("Got pull message: " + s)
case x ⇒ println("Got default case: " + x)
}
}
object TestPushPull extends App {
val address = "tcp://0.0.0.0:4100"
implicit val system = ActorSystem("zmqtest")
val pushSocket = system.newSocket(SocketType.Push, Connect(address))
val pull = system.actorOf(Props(new PullTestActor(address)), "PullTestActor")
//Try adding/removing this line
Thread.sleep(1000)
while (true) {
println("Pushing msg")
pushSocket ! ZMQMessage(Seq(Frame("msg")))
Thread.sleep(1000)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment