本文介绍单机环境快速启动 Apache ShenYu
网关。
在阅读本文档前,你需要先阅读部署先决条件文档来完成部署
shenyu
前的环境准备工作。
解压缩 apache-shenyu-${current.version}-bootstrap-bin.tar.gz
。 进入 bin 目录。
> windwos : start.bat > linux : ./start.sh
参考本地模式进行选择器及规则的配置。
示例:
http://127.0.0.1:8080/helloworld
,直接访问将返回如下{ "name" : "Shenyu", "data" : "hello world" }
Headers 中添加
localKey: 123456
。如果需要自定义 localKey,可以使用 sha512 工具根据明文生成 key,并更新shenyu.local.sha512Key
属性。请求方式POST,地址
http://localhost:9195/shenyu/plugin/selectorAndRules
,body 选择raw json,内容如下:
Headers localKey: 123456
{ "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": "/**" }] }] }
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": "/**" }] }] }'
http://localhost:9195/helloworld
请求服务,返回如下:{ "name" : "Shenyu", "data" : "hello world" }