ZeroMQ学习笔记:似乎无法顺利进行故障恢复
ZeroMQ(http://www.zeromq.org) 性能非常卓越,设计理念也非常牛,正在看文档中,这里记录一下遇到的一个问题:
服务端和客户端之间使用REQ , REP , 启动之后,不停杀掉Server进程,并重启(模拟故障恢复),多试几次之后,Client就会卡住,此时无论怎样都恢复不了。看tcp连接,发现是ESTABLISHED,而且由于zeromq提供的接口都无法感知网络状况,所以此时client压根不知道已经挂死了…
继续看文档,看看是不是自己写得不对…
public class Server { public static void main(String[] args) throws Exception { // Prepare our context and sockets final ZMQ.Context context = ZMQ.context(1); ZMQ.Socket socket = context.socket(ZMQ.REP); socket.bind("tcp://*:5555"); while (true) { byte[] request = socket.recv(0); System.out.println(new String(request)); while (socket.hasReceiveMore()) { request = socket.recv(0); System.out.println(new String(request)); } String s = new String(request); long r = Long.parseLong(s) + 100; // reply = request+100 socket.send(String.valueOf(r).getBytes(), 0); } } } |
public class Client { public static void main(String[] args) { // Prepare our context and socket final ZMQ.Context context = ZMQ.context(1); ZMQ.Socket socket = context.socket(ZMQ.REQ); System.out.println("Connecting to hello world server..."); socket.connect("tcp://localhost:5555"); while (true) { long l = System.nanoTime(); String s = String.valueOf(l); socket.send(s.getBytes(), 0); byte[] r = socket.recv(0); System.out.println(l + " + 100 = " + new String(r)); } } } |
原创文章如转载,请注明:转载自CODIGG [ http://www.codigg.com/ ]
本文链接地址:http://www.codigg.com/2011/01/zeromq-trouble-network-block/


一月 20th, 2011 at 19:59
一些参考:
https://github.com/zeromq/pyzmq/issues/issue/51
[回复]
一月 20th, 2011 at 20:12
http://comments.gmane.org/gmane.network.zeromq.devel/6285
[回复]
二月 17th, 2011 at 17:29
很久没来了过来看看~
[回复]
三月 13th, 2011 at 01:06
也好久没来了…
[回复]