Reference: http://iyuan.iteye.com/blog/974040
Model Description:
1. upstream (Task release)
2. Workers (intermediate, specific work)
3. downstream (signal collection or work result collection)
Code:
Push:
Package COM. zeromq. test. push_pull; import Org. zeromq. zmq;/*** @ author larry * @ email larry.lv.word@gmail.com * @ version 11:30:46 */public class push_demo {public static void main (string [] ARGs) {zmq. context context = zmq. context (1); zmq. socket sync = context. socket (zmq. push); sync. connect ("TCP: // localhost: 5564"); sync. send ("". getbytes (), 0); int update_nbr; For (update_nbr = 0; update_nbr <10; update_nbr ++) {sync. send ("rhubarb ". getbytes (), zmq. noblock);} Sync. send ("end ". getbytes (), 0 );}}
Pull:
/*****/Package COM. zeromq. test. push_pull; import Org. zeromq. zmq;/*** @ author larry * @ email larry.lv.word@gmail.com * @ version 11:37:46 */public class pull_demo {public static void main (string [] ARGs) {zmq. context context = zmq. context (1); zmq. socket sync = context. socket (zmq. pull); sync. BIND ("TCP: // *: 5564"); sync. recv (0); int update_nbr = 0; while (true) {byte [] stringvalue = Sync. recv (0); string = new string (stringvalue); If (string. equals ("end") {break;} update_nbr ++; system. out. println ("received" + update_nbr + "updates.: "+ String);} Sync. close (); context. term ();}}