node-zookeeper运行在node0.8.2上好像有问题,还是哪个版本都有问题,谁玩过吗?指教一下啊。
我说清楚点吧 node.js 0.8.2 zookeeper 默认配置 node-zookeeper里面有个example.js,只是把zk.close ();给注释了,然后起一个http端口,让server一直保持在线。运行之后,zookeeper是会建立一个临时节点,但node.js并没有关闭,临时节点几秒钟之后就会消失。同样的zookeeper用java就没有任何问题。 我当中出什么错了吗?
function ZkClient(hosts){
this.zk = newZk(hosts, this);//
}
function newZk(hosts, zkClient){
var zk = new ZOOKEEPER();
var timeout = 60000;
var options = {connect:hosts, timeout:timeout, debug_level:ZOOKEEPER.ZOO_LOG_LEVEL_INFO, host_order_deterministic:false};
zk.init (options);
zk.on('connect', function(zkk){
console.log('zk session established, id = %s', zkk.client_id);
});
zk.on('close',function(zkk){
console.log("zk session close...");
//zkClient.zk = newZk(hosts, zkClient);
});
return zk;
}
var zk = new ZkClient(hosts).zk;
/**
* @path /thrift_services/nodis
* @node 192.168.126:9998
*/
exports.registerService = function(path, node){
// EPHEMERAL:创建临时节点,ZooKeeper在感知连接机器宕机后会清除它创建的瞬节点
zk.a_create(path + '/' + node, '', ZOOKEEPER.ZOO_EPHEMERAL, function (rc, error, path) {
if (rc != 0){//error occurs
console.log('node create result: %d, error: "%s", path: %s', rc, error, path);
}
else{
console.log('node create result: ok, path: %s', path);
}
});
};
节点不会消失。。。
@vincentking 注意timeout时间的设置,以及zookeeper本身的参数设置。从java的源码看,这个timeout很坑爹。node-zookeeper使用的是c的client,没看过源码,实现应该差不多。
2012-07-26 11:11:32,023:26169:ZOO_ERROR@handle_socket_error_msg@1719: Socket [127.0.0.1:2181] zk retcode=-4, errno=112(Host is down): failed while receiving a server response 2012-07-26 11:11:32,023:26169:ZOO_ERROR@zk_io_cb@247: yield:zookeeper_process returned error: -4 - connection loss
google了下,果然是 connection loss 的问题,问题是你怎么没有啊???你的zk的配置是怎么样的?
//The number of milliseconds of each tick
tickTime=2000
//The number of ticks that the initial
//synchronization phase can take
initLimit=10
//The number of ticks that can pass between
//sending a request and getting an acknowledgement
syncLimit=5
//the directory where the snapshot is stored.
dataDir=../../data
//the port at which the clients will connect
clientPort=2181
你试试看,这个是测试机上的,还没出过问题