Skip to content

Instantly share code, notes, and snippets.

@pphetra
Created September 3, 2010 10:53
Show Gist options
  • Save pphetra/563740 to your computer and use it in GitHub Desktop.
Save pphetra/563740 to your computer and use it in GitHub Desktop.
import org.springframework.beans.factory.InitializingBean
import org.zeromq.ZMQ
class ParseService implements InitializingBean {
def pullSocket
def pubSocket
def running = true
def pollingRate = 200
void afterPropertiesSet() {
def ctx = ZMQ.context(1)
pullSocket = ctx.socket(ZMQ.PULL)
pullSocket.connect("tcp://xxx:5000")
pubSocket = ctx.socket(ZMQ.PUB)
pubSocket.bind("tcp://127.0.0.1:5000")
scannerThread = new Thread() {
while(running) {
def buff = pullSocket.recv(0)
process(buff)
try {
Thread.sleep(pollingRate)
} catch (e) {}
}
}
scannerThread.start()
}
def process(byte[] buff) {
// first 10 bytes is id
// rest is stream
def type = ....
pubSocket.send("${id}:${type}".bytes, 0)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment