2018-05-18 21:36:43 +00:00
|
|
|
local balancer_resty = require("balancer.resty")
|
|
|
|
local resty_roundrobin = require("resty.roundrobin")
|
|
|
|
local util = require("util")
|
2018-06-19 08:46:49 +00:00
|
|
|
local split = require("util.split")
|
2018-05-18 21:36:43 +00:00
|
|
|
|
|
|
|
local _M = balancer_resty:new({ factory = resty_roundrobin, name = "round_robin" })
|
|
|
|
|
|
|
|
function _M.new(self, backend)
|
|
|
|
local nodes = util.get_nodes(backend.endpoints)
|
|
|
|
local o = { instance = self.factory:new(nodes) }
|
|
|
|
setmetatable(o, self)
|
|
|
|
self.__index = self
|
|
|
|
return o
|
|
|
|
end
|
|
|
|
|
|
|
|
function _M.balance(self)
|
|
|
|
local endpoint_string = self.instance:find()
|
2018-06-19 08:46:49 +00:00
|
|
|
return split.split_pair(endpoint_string, ":")
|
2018-05-18 21:36:43 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return _M
|