zhc00 commented on code in PR #8:
URL:
https://github.com/apache/incubator-shenyu-nginx/pull/8#discussion_r895862440
##########
example/etcd/nginx.conf:
##########
@@ -23,14 +23,14 @@ events {
worker_connections 1024;
}
http {
- lua_shared_dict shenyu_storage 1m;
+ lua_shared_dict shenyu_storage 10m;
init_worker_by_lua_block {
local register = require("shenyu.register.etcd")
register.init({
shenyu_storage = ngx.shared.shenyu_storage,
balancer_type = "chash",
- etcd_base_url = "http://127.0.0.01:2379",
Review Comment:
typo, 127.0.0.1
##########
lib/shenyu/register/consul.lua:
##########
@@ -0,0 +1,78 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements. See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+
+local http = require("resty.http")
+local json = require("cjson")
+local balancer = require("ngx.balancer")
+
+local new_timer = ngx.timer.at
+local log = ngx.log
+local ERR = ngx.ERR
+
+local _M = {}
+
+_M._VERSION="0.1"
+
+function _M:sync()
+ local httpc = http.new()
+
+ local resp, err = httpc:request_uri(_M.uri, {
+ method = "GET",
+ path = _M.path,
+
+ })
+
+ local kvs = json.decode(resp.body)
+ local upstreams = {}
+ for i, v in ipairs(kvs) do
+ log(ERR, v.ServiceAddress)
+ log(ERR, v.ServicePort)
+ upstreams[i] = {ip=v.ServiceAddress, port=v.ServicePort}
+ end
+ _M.storage:set("server_list", json.encode(upstreams))
+
+end
+
+function _M:get_server_list()
+ local upstreams_str = _M.storage:get("server_list");
+ local tmp_upstreams = json.decode(upstreams_str);
+ return tmp_upstreams;
+end
+
+function _M:pick_and_set_peer()
+ local tmp_upstreams = _M.get_server_list();
+ local ip_port = tmp_upstreams[math.random(1, table.getn(tmp_upstreams))];
Review Comment:
let us use `lua-resty-balancer`
##########
lib/shenyu/register/consul.lua:
##########
@@ -0,0 +1,76 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements. See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+
+local http = require("resty.http")
+local json = require("cjson")
+local balancer = require("ngx.balancer")
+
+local new_timer = ngx.timer.at
+local log = ngx.log
+local ERR = ngx.ERR
+
+local _M = {}
+
+_M._VERSION="0.1"
+
+local function sync()
+ local httpc = http.new()
+
+ local resp, err = httpc:request_uri(_M.uri, {
+ method = "GET",
+ path = _M.path,
+
Review Comment:
first, remove the empty line(L36)
then, maybe, let us keep the same argument list. I think the `path` could
make users confusing.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]