Skip to content

Commit

Permalink
Feat/wrpc (#8357)
Browse files Browse the repository at this point in the history
This commit add the wRPC protocol and uses it for the DP/CP connection in hybrid mode.

The wRPC protocol is a generic, bidirectional RPC protocol that allows multiple services on the same persistent (WebSocket) connection.
  • Loading branch information
javierguerragiraldez authored Mar 31, 2022
1 parent 5b7676c commit 4d4b90c
Show file tree
Hide file tree
Showing 35 changed files with 3,846 additions and 891 deletions.
5 changes: 5 additions & 0 deletions kong-2.8.0-0.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ build = {
["kong.clustering"] = "kong/clustering/init.lua",
["kong.clustering.data_plane"] = "kong/clustering/data_plane.lua",
["kong.clustering.control_plane"] = "kong/clustering/control_plane.lua",
["kong.clustering.wrpc_data_plane"] = "kong/clustering/wrpc_data_plane.lua",
["kong.clustering.wrpc_control_plane"] = "kong/clustering/wrpc_control_plane.lua",
["kong.clustering.compat.removed_fields"] = "kong/clustering/compat/removed_fields.lua",

["kong.cluster_events"] = "kong/cluster_events/init.lua",
Expand Down Expand Up @@ -136,6 +138,9 @@ build = {
["kong.tools.sandbox"] = "kong/tools/sandbox.lua",
["kong.tools.uri"] = "kong/tools/uri.lua",
["kong.tools.kong-lua-sandbox"] = "kong/tools/kong-lua-sandbox.lua",
["kong.tools.protobuf"] = "kong/tools/protobuf.lua",
["kong.tools.wrpc"] = "kong/tools/wrpc.lua",
["kong.tools.channel"] = "kong/tools/channel.lua",

["kong.runloop.handler"] = "kong/runloop/handler.lua",
["kong.runloop.certificate"] = "kong/runloop/certificate.lua",
Expand Down
29 changes: 26 additions & 3 deletions kong/clustering/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,20 @@ function _M.new(conf)
local key = assert(pl_file.read(conf.cluster_cert_key))
self.cert_key = assert(ssl.parse_pem_priv_key(key))

self.child = require("kong.clustering." .. conf.role).new(self)
print("role: ", conf.role, " protocol: ", conf.cluster_protocol)

if conf.role == "control_plane" then
self.json_handler = require("kong.clustering.control_plane").new(self)
self.wrpc_handler = require("kong.clustering.wrpc_control_plane").new(self)

else
local clustering_submodule = conf.role
if conf.cluster_protocol == "wrpc" then
clustering_submodule = "wrpc_" .. clustering_submodule
end

self.child = require("kong.clustering." .. clustering_submodule).new(self)
end

return self
end
Expand Down Expand Up @@ -184,7 +197,11 @@ end


function _M:handle_cp_websocket()
return self.child:handle_cp_websocket()
return self.json_handler:handle_cp_websocket()
end

function _M:handle_wrpc_websocket()
return self.wrpc_handler:handle_cp_websocket()
end


Expand All @@ -198,7 +215,13 @@ function _M:init_worker()
return { name = p.name, version = p.handler.VERSION, }
end, self.plugins_list)

self.child:init_worker()
for _, ch in ipairs{"child", "json_handler", "wrpc_handler"} do
local child = self[ch]
if child then
child:init_worker()
end
end
--self.child:init_worker()
end


Expand Down
Loading

0 comments on commit 4d4b90c

Please sign in to comment.