基于customerId来实现

news/2024/11/7 21:04:38/

定义两个upstream,他们和service及route的关系如下:
在这里插入图片描述
这里我们使用

0、将下面的这个spring boot项目在192.168.19.50上进行部署

KongDemoApplication.java

package com.example.kongdemo;import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;@SpringBootApplication
@RestController
public class KongDemoApplication {@Value("${server.port}")private String port;@Value("${spring.range}")private String range;public static void main(String[] args) {SpringApplication.run(KongDemoApplication.class, args);}@GetMapping("/hello")public String hello(){return "hello : " + port + ";range:" + range;}@GetMapping("/hello/sub")public String subHello(){return "sub-hello: " + port + ";range:" + range;}}

applicaton.properties

server.port=8080
spring.range=CN

项目打成jar包后,在192.168.19.50机器按照如下命令运行6个实例:
nohup java -jar kong-demo-0.0.1-SNAPSHOT.jar --server.port=8080 --spring.range=CN > 8080.txt &
nohup java -jar kong-demo-0.0.1-SNAPSHOT.jar --server.port=8081 --spring.range=CN > 8081.txt &
nohup java -jar kong-demo-0.0.1-SNAPSHOT.jar --server.port=8082 --spring.range=CN > 8082.txt &
nohup java -jar kong-demo-0.0.1-SNAPSHOT.jar --server.port=8083 --spring.range=OT > 8083.txt &
nohup java -jar kong-demo-0.0.1-SNAPSHOT.jar --server.port=8084 --spring.range=OT > 8084.txt &
nohup java -jar kong-demo-0.0.1-SNAPSHOT.jar --server.port=8085 --spring.range=OT > 8085.txt &

1、创建cn_upstream及ot_upstream

1.1 创建cn_upstream

[root@min ~]# curl -X POST http://localhost:8001/upstreams \--data name=cn_upstream
{"hash_fallback":"none","hash_fallback_header":null,"hash_fallback_query_arg":null,"hash_fallback_uri_capture":null,"host_header":null,"tags":null,"updated_at":1685570147,"name":"cn_upstream","hash_on":"none","hash_on_header":null,"client_certificate":null,"hash_on_query_arg":null,"hash_on_uri_capture":null,"use_srv_name":false,"slots":10000,"hash_on_cookie":null,"hash_on_cookie_path":"/","healthchecks":{"active":{"healthy":{"interval":0,"successes":0,"http_statuses":[200,302]},"unhealthy":{"interval":0,"http_failures":0,"timeouts":0,"http_statuses":[429,404,500,501,502,503,504,505],"tcp_failures":0},"http_path":"/","https_sni":null,"type":"http","concurrency":10,"https_verify_certificate":true,"headers":null,"timeout":1},"threshold":0,"passive":{"healthy":{"successes":0,"http_statuses":[200,201,202,203,204,205,206,207,208,226,300,301,302,303,304,305,306,307,308]},"unhealthy":{"timeouts":0,"http_failures":0,"http_statuses":[429,500,503],"tcp_failures":0},"type":"http"}},"id":"5aae2f66-3fb5-461d-9189-e30fa80a2d61","algorithm":"round-robin","created_at":1685570147}

1.2 创建ot_upstream

[root@min ~]# curl -X POST http://localhost:8001/upstreams   --data name=ot_upstream
{"hash_fallback":"none","hash_fallback_header":null,"hash_fallback_query_arg":null,"hash_fallback_uri_capture":null,"host_header":null,"tags":null,"updated_at":1685570784,"name":"ot_upstream","hash_on":"none","hash_on_header":null,"client_certificate":null,"hash_on_query_arg":null,"hash_on_uri_capture":null,"use_srv_name":false,"slots":10000,"hash_on_cookie":null,"hash_on_cookie_path":"/","healthchecks":{"active":{"healthy":{"interval":0,"successes":0,"http_statuses":[200,302]},"unhealthy":{"interval":0,"http_failures":0,"timeouts":0,"http_statuses":[429,404,500,501,502,503,504,505],"tcp_failures":0},"http_path":"/","https_sni":null,"type":"http","concurrency":10,"https_verify_certificate":true,"headers":null,"timeout":1},"threshold":0,"passive":{"healthy":{"successes":0,"http_statuses":[200,201,202,203,204,205,206,207,208,226,300,301,302,303,304,305,306,307,308]},"unhealthy":{"timeouts":0,"http_failures":0,"http_statuses":[429,500,503],"tcp_failures":0},"type":"http"}},"id":"918d9fec-c274-48df-880d-d522aa0b7482","algorithm":"round-robin","created_at":1685570784}

2、为cn_upstream、ot_upstream添加target

2.1、为cn_upstream添加target

curl -X POST http://localhost:8001/upstreams/cn_upstream/targets \--data target='192.168.19.50:8080'
curl -X POST http://localhost:8001/upstreams/cn_upstream/targets \--data target='192.168.19.50:8081'curl -X POST http://localhost:8001/upstreams/cn_upstream/targets \--data target='192.168.19.50:8082'

在这里插入图片描述

2.2、为op_upstream添加target

curl -X POST http://localhost:8001/upstreams/ot_upstream/targets \--data target='192.168.19.50:8083'
curl -X POST http://localhost:8001/upstreams/ot_upstream/targets \--data target='192.168.19.50:8084'curl -X POST http://localhost:8001/upstreams/ot_upstream/targets \--data target='192.168.19.50:8085'

3、创建service

3.1、创建cn_service

创建cn_service,并将其host指向cn_upstream

[root@min ~]# curl -i -s -X POST http://localhost:8001/services \--data name=cn_service \--data host='cn_upstream'
HTTP/1.1 201 Created
Date: Wed, 31 May 2023 22:10:00 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
Access-Control-Allow-Origin: http://localhost:8002
X-Kong-Admin-Request-ID: sUQcvdGQ4m002ZnQysRNnFaEydvU0edv
vary: Origin
Access-Control-Allow-Credentials: true
Content-Length: 371
X-Kong-Admin-Latency: 9
Server: kong/3.3.0.0-enterprise-edition{"connect_timeout":60000,"read_timeout":60000,"protocol":"http","host":"cn_upstream","updated_at":1685571000,"name":"cn_service","retries":5,"write_timeout":60000,"id":"39e44a6e-dfdf-4a32-85ba-db003f424073","tls_verify":null,"port":80,"tls_verify_depth":null,"enabled":true,"client_certificate":null,"path":null,"ca_certificates":null,"created_at":1685571000,"tags":null}

在这里插入图片描述

3.1、创建ot_service

创建ot_service,并将其host指向ot_upstream

 curl -i -s -X POST http://localhost:8001/services \--data name=ot_service \--data host='ot_upstream'

在这里插入图片描述

4、为cn_service和ot_service创建route

4.1、为cn_service创建route,path为:/cn_service

curl -i -X POST http://localhost:8001/services/cn_service/routes \--data 'paths[]=/cn_service' \--data name=cn_route

在这里插入图片描述

4.1、为cn_service创建route,path为:/cn_service

curl -i -X POST http://localhost:8001/services/ot_service/routes \--data 'paths[]=/ot_service' \--data name=ot_route

在这里插入图片描述

5、测试的搭建情况

如果访问192.168.19.50:8000/cn_service/hello将会被代理到cn_upstream上,即会被192.168.19.50:8080/hello、192.168.19.50:8081/hello、192.168.19.50:8082/hello三个服务中的一个处理

如果访问192.168.19.50:8000/ot_service/hello将会被代理到cn_upstream上,即会被192.168.19.50:8083/hello、192.168.19.50:8084/hello、192.168.19.50:8085/hello三个服务中的一个处理

[root@min ~]# curl http://192.168.19.50:8000/cn_service/hello
hello : 8082;range:CN[root@min ~]# curl http://192.168.19.50:8000/cn_service/hello
hello : 8080;range:CN[root@min ~]# curl http://192.168.19.50:8000/cn_service/hello
hello : 8080;range:CN[root@min ~]# curl http://192.168.19.50:8000/cn_service/hello
hello : 8081;range:CN[root@min ~]# curl http://192.168.19.50:8000/cn_service/hello
hello : 8082;range:CN[root@min ~]# [root@min ~]# curl http://192.168.19.50:8000/ot_service/hello
hello : 8085;range:OT[root@min ~]# curl http://192.168.19.50:8000/ot_service/hello
hello : 8083;range:OT[root@min ~]# curl http://192.168.19.50:8000/ot_service/hello
hello : 8084;range:OT[root@min ~]# 

6、启用插件

curl -X POST http://localhost:8001/plugins/
–data “name=acl”
–data “config.allow=group1”
–data “config.allow=group2”
–data “config.hide_groups_header=true”


http://www.ppmy.cn/news/153571.html

相关文章

罗技G29方向盘与Unity的连接交互

首先需要罗技游戏软件驱动,然后就是与Unity连接的SDK了。 发现从Assets Store上下载的Logi Gaming SDK直接导入会报错,缺失dll文件,于是去罗技官网下载了SDK,从里面找到了所缺失的dll文件,导出了一个可以正常使用的无报…

罗技驱动为什么无法识别我的鼠标?

现在很多用户都在使用罗技鼠标,如果罗技的驱动在使用时遇到了无法识别鼠标,或者检测不到鼠标的问题,那么很多都是因为鼠标或接口故障,也可能是安装的驱动版本错误导致。 罗技驱动为什么无法识别我的鼠标? 一、可能是鼠…

高亮度区域检测(二维通道转三通道)opencv

将一张图中亮度超过128的区域变成红色输出 def reshape_gray_to_color( img):"""一个img的shape等于img.shape (319, 460) ,将该img的shape变成img.shape (319, 460, 3)"""# 创建新的形状(在最后面加入一个“3”以表示三个颜色通道&a…

罗技G304鼠标的按键宏定义

先下载罗技驱动: https://download01.logi.com/web/ftp/pub/techsupport/gaming/LGS_9.02.65_x64_Logitech.exe 下载完以后直接open, 选择鼠标进行自定义板载配置, 主要喜欢的是以上两个定义,如果你也是码农,会极大…

Unity罗技方向盘接入

要想在Unity中接入罗技方向盘的数据,首先必须安装驱动,并且打开安装的软件,否则在Unity中会一直连接不成功。状态如下: 然后下载相应的开发包Logitech SDK即可,需要替换相应的LogitechSteeringWheelEnginesWrapper.dll…

Unity3D和罗技方向盘使用方法链接总结

链接总结 Unity3D 罗技G29开发笔记:https://blog.csdn.net/Sakura_Jun/article/details/87718845 Unity开发 罗技方向盘 G29 白话:https://blog.csdn.net/qq_28244783/article/details/89402515 Unity3d 与罗技G29交互,数据获取:…

罗技G29方向盘Mac驱动

罗技G29方向盘信息和Mac驱动 一、下载 网址:https://support.logi.com/hc/zh-cn/articles/360024850133–%E4%B8%8B%E8%BD%BD-G29-Driving-Force-%E8%B5%9B%E8%BD%A6%E6%96%B9%E5%90%91%E7%9B%98 二、安装 打开下载的zip安装包,即可下载安装&#x…