2018-05-18 17:36:43 -04:00
|
|
|
local balancer_resty = require("balancer.resty")
|
|
|
|
|
local resty_roundrobin = require("resty.roundrobin")
|
|
|
|
|
local util = require("util")
|
|
|
|
|
|
2020-06-06 23:07:06 +08:00
|
|
|
local setmetatable = setmetatable
|
|
|
|
|
|
2018-05-18 17:36:43 -04:00
|
|
|
local _M = balancer_resty:new({ factory = resty_roundrobin, name = "round_robin" })
|
|
|
|
|
|
|
|
|
|
function _M.new(self, backend)
|
|
|
|
|
local nodes = util.get_nodes(backend.endpoints)
|
2018-09-18 14:05:32 -04:00
|
|
|
local o = {
|
|
|
|
|
instance = self.factory:new(nodes),
|
2018-11-13 15:44:57 +04:00
|
|
|
traffic_shaping_policy = backend.trafficShapingPolicy,
|
|
|
|
|
alternative_backends = backend.alternativeBackends,
|
2018-09-18 14:05:32 -04:00
|
|
|
}
|
2018-05-18 17:36:43 -04:00
|
|
|
setmetatable(o, self)
|
|
|
|
|
self.__index = self
|
|
|
|
|
return o
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function _M.balance(self)
|
2018-05-30 17:14:28 -04:00
|
|
|
return self.instance:find()
|
2018-05-18 17:36:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return _M
|