nginx-upsync-module
nginx-upsync-module copied to clipboard
Nginx upsync 1.8.x
支持zookeeper
- 使用zookeeper的rest api。由于zookeeper 的rest api不支持recursive参数,故修改zookeer rest api源码,以支持recursive。 https://github.com/zexuan/zookeeper/blob/trunk/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/ZNodeResource.java https://github.com/zexuan/zookeeper/blob/trunk/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/jaxb/ZChildrenStat.java
2.也可以做一个http代理,php代码如下: ` date_default_timezone_set('PRC'); $url = "http://127.0.0.1:9998/znodes/v1/upstreams/test";
function send($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt ($ch, CURLOPT_URL, $url);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
function getChildren($url) {
$rs = send($url . "?view=children");
$rs = json_decode($rs, true);
$children = $rs['children'];
$arr = array();
foreach($children as $child) {
$data = send($url . '/' . $child . '?view=data');
$arr[] = json_decode($data, true);
}
return $arr;
}
function response($url) {
$res = array();
$children = getChildren($url);
if(!empty($children)) {
$res['children'] = $children;
}
header('Content-type: application/json; charset=utf-8');
echo json_encode($res);
}
response($url);
`
测试配置文件 nginx.conf upsync 127.0.0.1:9998/znodes/v1/upstreams/test upsync_timeout=6m upsync_interval=500ms upsync_type=zk strong_dependency=off;
非常、非常感谢,支持zookeeper 超赞!
看你的说明是修改了zookeeper 的源码,这样是不是有点tricky?能不能不修改zookeeper,从而模块更加通用?并不一定必须要支持recursive,这个可行么?
方便告知你的邮箱吗?非常感谢!
ok, I will try. 我的邮箱:[email protected]
赞!
感谢!