Http快速开始

本文档将演示了如何快速使用Http请求接入Soul网关。您可以直接在工程下找到本文档的示例代码

环境准备

请参考配置网关环境并启动soul-admin

引入网关对http的代理插件

  • 在网关的 pom.xml 文件中增加如下依赖:
  1. <!--if you use http proxy start this-->
  2. <dependency>
  3. <groupId>org.dromara</groupId>
  4. <artifactId>soul-spring-boot-starter-plugin-divide</artifactId>
  5. <version>${last.version}</version>
  6. </dependency>
  7. <dependency>
  8. <groupId>org.dromara</groupId>
  9. <artifactId>soul-spring-boot-starter-plugin-httpclient</artifactId>
  10. <version>${last.version}</version>
  11. </dependency>

启动soul-bootstrap项目。

运行soul-examples-http项目

下载soul-examples-http

运行org.dromara.soul.examples.http.SoulTestHttpApplicationmain方法启动项目。

成功启动会有如下日志:

  1. 2021-02-10 00:57:07.561 INFO 3700 --- [pool-1-thread-1] o.d.s.client.common.utils.RegisterUtils : http client register success: {"appName":"http","context":"/http","path":"/http/test/**","pathDesc":"","rpcType":"http","host":"192.168.50.13","port":8188,"ruleName":"/http/test/**","enabled":true,"registerMetaData":false}
  2. 2021-02-10 00:57:07.577 INFO 3700 --- [pool-1-thread-1] o.d.s.client.common.utils.RegisterUtils : http client register success: {"appName":"http","context":"/http","path":"/http/order/save","pathDesc":"Save order","rpcType":"http","host":"192.168.50.13","port":8188,"ruleName":"/http/order/save","enabled":true,"registerMetaData":false}
  3. 2021-02-10 00:57:07.587 INFO 3700 --- [pool-1-thread-1] o.d.s.client.common.utils.RegisterUtils : http client register success: {"appName":"http","context":"/http","path":"/http/order/path/**/name","pathDesc":"","rpcType":"http","host":"192.168.50.13","port":8188,"ruleName":"/http/order/path/**/name","enabled":true,"registerMetaData":false}
  4. 2021-02-10 00:57:07.596 INFO 3700 --- [pool-1-thread-1] o.d.s.client.common.utils.RegisterUtils : http client register success: {"appName":"http","context":"/http","path":"/http/order/findById","pathDesc":"Find by id","rpcType":"http","host":"192.168.50.13","port":8188,"ruleName":"/http/order/findById","enabled":true,"registerMetaData":false}
  5. 2021-02-10 00:57:07.606 INFO 3700 --- [pool-1-thread-1] o.d.s.client.common.utils.RegisterUtils : http client register success: {"appName":"http","context":"/http","path":"/http/order/path/**","pathDesc":"","rpcType":"http","host":"192.168.50.13","port":8188,"ruleName":"/http/order/path/**","enabled":true,"registerMetaData":false}
  6. 2021-02-10 00:57:08.023 INFO 3700 --- [ main] o.s.b.web.embedded.netty.NettyWebServer : Netty started on port(s): 8188
  7. 2021-02-10 00:57:08.026 INFO 3700 --- [ main] o.d.s.e.http.SoulTestHttpApplication : Started SoulTestHttpApplication in 2.555 seconds (JVM running for 3.411)

开启divide 插件来处理http请求

  • soul-admin 插件管理中,把divide 插件设置为开启。

测试Http请求

soul-examples-http项目成功启动之后会自动把加 @SoulSpringMvcClient 注解的接口方法注册到网关。

打开插件管理->divide 可以看到插件规则配置列表

Http快速开始 - 图1

下面使用postman模拟http的方式来请求你的http服务

Http快速开始 - 图2