单机快速部署

本文介绍单机环境快速启动 Apache ShenYu 网关。

环境准备

  • 本地正确安装JDK1.8+

启动 Apache ShenYu Bootstrap

  1. > windwos : start.bat
  2. > linux : ./start.sh

选择器及规则配置

参考本地模式进行选择器及规则的配置。

示例:

  • 如服务地址是http://127.0.0.1:8080/helloworld,直接访问将返回如下
  1. {
  2. "name" : "Shenyu",
  3. "data" : "hello world"
  4. }
  • 按照如下进行选择器和规则配置

使用postman

请求方式POST,地址http://localhost:9195/shenyu/plugin/selectorAndRules,body 选择raw json,内容如下:

  1. {
  2. "pluginName": "divide",
  3. "selectorHandler": "[{\"upstreamUrl\":\"127.0.0.1:8080\"}]",
  4. "conditionDataList": [{
  5. "paramType": "uri",
  6. "operator": "match",
  7. "paramValue": "/**"
  8. }],
  9. "ruleDataList": [{
  10. "ruleHandler": "{\"loadBalance\":\"random\"}",
  11. "conditionDataList": [{
  12. "paramType": "uri",
  13. "operator": "match",
  14. "paramValue": "/**"
  15. }]
  16. }]
  17. }

使用curl

  1. curl --location --request POST 'http://localhost:9195/shenyu/plugin/selectorAndRules' \
  2. --header 'Content-Type: application/json' \
  3. --data-raw '{
  4. "pluginName": "divide",
  5. "selectorHandler": "[{\"upstreamUrl\":\"127.0.0.1:8080\"}]",
  6. "conditionDataList": [{
  7. "paramType": "uri",
  8. "operator": "match",
  9. "paramValue": "/**"
  10. }],
  11. "ruleDataList": [{
  12. "ruleHandler": "{\"loadBalance\":\"random\"}",
  13. "conditionDataList": [{
  14. "paramType": "uri",
  15. "operator": "match",
  16. "paramValue": "/**"
  17. }]
  18. }]
  19. }'
  • 通过http://localhost:9195/helloworld请求服务,返回如下:
  1. {
  2. "name" : "Shenyu",
  3. "data" : "hello world"
  4. }