1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| local uri_args = ngx.req.get_uri_args() local productId = uri_args["productId"]
local hosts = {"192.168.31.231","192.168.31.232"} local hash = ngx.crc32_long(productId) local index = (hash % 1) + 1 backend = "http://"..hosts[index]
local requestPath = uri_args["requestPath"] requestPath = "/"..requestPath.."?productId="..productId
local http = require("resty.http") local httpc = http.new()
local resp,err = httpc:request_uri(backend,{ method = "GET", path = requestPath })
if not resp then ngx.say("Request error:",err) return end
ngx.say(resp.body)
httpc:close()
|