-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
feat(clustering/rpc): support jsonrpc notification #13948
Conversation
33fe9ec
to
e77cafc
Compare
509a30d
to
2bfecec
Compare
@@ -151,7 +162,7 @@ function _M:start() | |||
ngx_log(ngx_DEBUG, "[rpc] got RPC call: ", payload.method, " (id: ", payload.id, ")") | |||
|
|||
local dispatch_cb = self.manager.callbacks.callbacks[payload.method] | |||
if not dispatch_cb then | |||
if not dispatch_cb and payload.id then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the Json-RPC 2.0 spec, I think the reply MUST contain id
field. So could we check whether there is a payload.id
right after the line local payload = decompress_payload(data)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
like
local payload = decompress_payload(data)
-- check id firstly
if not payload.id then
return error_log("not found id")
end
if type(payload.id) ~= number then
return error_log("invalid id: not a number")
end
-- From now on, we assure that payload.id exists and it is a number
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the examles in json rpc spec:
--> {"jsonrpc": "2.0", "method": "update", "params": [1,2,3,4,5]}
--> {"jsonrpc": "2.0", "method": "foobar"}
kong/clustering/rpc/manager.lua
Outdated
|
||
return nil, fut.error.message | ||
end | ||
|
||
|
||
function _M:notify(node_id, method, ...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
diff with _M:call(node_id, method, ...)
, I think we could combine them into one
@@ -1,4 +1,4 @@
-function _M:notify(node_id, method, ...)
+function _M:call(node_id, method, ...)
local cap = utils.parse_method_name(method)
local res, err = self:_find_node_and_check_capability(node_id, cap)
@@ -30,8 +30,25 @@ function _M:notify(node_id, method, ...)
assert(res == "concentrator")
-- try concentrator
- local fut = future.new(node_id, self.concentrator, method, params, true)
+ local fut = future.new(node_id, self.concentrator, method, params)
assert(fut:start())
- return true
+ local ok, err = fut:wait(5)
+
+ if err then
+ ngx_log(ngx_DEBUG, "[rpc] ", method, " failed, err: ", err)
+
+ return nil, err
+ end
+
+ if ok then
+ ngx_log(ngx_DEBUG, "[rpc] ", method, " succeeded")
+
+ return fut.result
+ end
+
+ ngx_log(ngx_DEBUG, "[rpc] ", method, " failed, err: ", fut.error.message)
+
+ return nil, fut.error.message
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could do it later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refactored.
We should add test cases for it later. |
dda12a1
to
3d6f84f
Compare
cd08089
to
047fcf9
Compare
Successfully created cherry-pick PR for |
Summary
KAG-5893
Checklist
changelog/unreleased/kong
orskip-changelog
label added on PR if changelog is unnecessary. README.mdIssue reference
Fix #[issue number]