《开源精选》是我们分享Github、Gitee等开源社区中优质项目的栏目,包括技术、学习、实用与各种有趣的内容。本期推荐的是Java Reactor 开发的响应式 API 网关——ShenYu。
Apache ShenYu 一款使用 Java Reactor 开发的响应式 API 网关。以其高性能,动态灵活的流量管控,热插拔,易部署等特性,开箱即用为用户提供整套全生命周期的 API 网关,包含 API 注册、服务代理、协议转换与 API 治理等功能。
运行ShenYu管理员:
> docker pull apache/shenyu-admin> docker network create shenyu> docker run -d -p 9095:9095 --net shenyu apache/shenyu-admin
运行引导程序:
> docker network create shenyu> docker pull apache/shenyu-bootstrap> docker run -d -p 9195:9195 --net shenyu apache/shenyu-bootstrap
设置路由器:
{ "name" : "Shenyu", "data" : "hello world"}
添加localKey: 123456到header。如果需要自定义localKey,可以使用sha512工具根据明文生成key并更新shenyu.local.sha512Key属性。
curl --location --request POST 'http://localhost:9195/shenyu/plugin/selectorAndRules' \--header 'Content-Type: application/json' \--header 'localKey: 123456' \--data-raw '{ "pluginName": "divide", "selectorHandler": "[{\"upstreamUrl\":\"127.0.0.1:8080\"}]", "conditionDataList": [{ "paramType": "uri", "operator": "match", "paramValue": "/**" }], "ruleDataList": [{ "ruleHandler": "{\"loadBalance\":\"random\"}", "conditionDataList": [{ "paramType": "uri", "operator": "match", "paramValue": "/**" }] }]}'
{ "name" : "Shenyu", "data" : "hello world"}
由于所有数据都已在 JVM 中使用 ConcurrentHashMap 进行缓存,因此速度非常快。
当用户在后台管理中更改配置信息时,Apache ShenYu 通过监听 ZooKeeper 节点(或 WebSocket 推送、HTTP 长轮询)来动态更新缓存。
—END—
开源协议:Apache2.0
开源地址:https://github.com/apache/shenyu
留言与评论(共有 0 条评论) “” |