-
-
Save inazt/563742 to your computer and use it in GitHub Desktop.
Grails Service ZeroMQ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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