Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nginx upsync 1.8.x #93

Open
wants to merge 4 commits into
base: nginx-upsync-1.8.x
Choose a base branch
from

Conversation

zexuan
Copy link

@zexuan zexuan commented Jul 15, 2016

支持zookeeper

  1. 使用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;

@xiaokai-wang
Copy link
Member

非常、非常感谢,支持zookeeper 超赞!

看你的说明是修改了zookeeper 的源码,这样是不是有点tricky?能不能不修改zookeeper,从而模块更加通用?并不一定必须要支持recursive,这个可行么?

方便告知你的邮箱吗?非常感谢!

@zexuan
Copy link
Author

zexuan commented Jul 16, 2016

ok, I will try.
我的邮箱:[email protected]

@xiaokai-wang
Copy link
Member

赞!

感谢!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants