38. 【实战】基于nginx+lua+java完成多级缓存架构的核心业务逻辑

分发层nginx,lua应用,会将商品id,商品店铺id,都转发到后端的应用nginx

nginx+lua+java多级缓存流程

修改分发层nginx

  1. 分发层nginxeshop-cache03<192.168.0.108>vi /usr/hello/hello.conf
    在这里插入图片描述
location /product {
   
        default_type 'text/html';
        # lua_code_cache off;
        content_by_lua_file /usr/hello/lua/distribute.lua;
    }
  1. 修改lua脚本: vi /usr/hello/lua/distribute.lua
local uri_args = ngx.req.get_uri_args()
local productId = uri_args["productId"]
local shopId = uri_args["shopId"]

local host = {
   "192.168.0.106", "192.168.0.107"}
local hash = ngx.crc32_long(productId)
local index = (hash % 2) + 1
local backend = "http://"..host[index]

local requestPath = uri_args["requestPath"]
requestPath = "/"..requestPath.."?productId="..productId.."&shopId="..shopId

local http = require("resty.http")
local httpc = http.new()

local resp, err = httpc:request_uri(backend, {
   
    method = "GET",
    path = requestPath,
    keepalive=false
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值