Soul网关源码阅读05
作者:互联网
结合springcloud插件,发起http请求soul网关,体验springcloud代理
一、环境准备
1、soul-bootstrap 引入网关springCloud的插件支持
- 在网关的 pom.xml 文件中引入如下依赖
<!--soul springCloud plugin start-->
<dependency>
<groupId>org.dromara</groupId>
<artifactId>soul-spring-boot-starter-plugin-springcloud</artifactId>
<version>${last.version}</version>
</dependency>
<dependency>
<groupId>org.dromara</groupId>
<artifactId>soul-spring-boot-starter-plugin-httpclient</artifactId>
<version>${last.version}</version>
</dependency>
<!--soul springCloud plugin end-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-commons</artifactId>
<version>2.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
<version>2.2.0.RELEASE</version>
</dependency>
- 使用 eureka 作为 springCloud的注册中心,在网关的 pom.xml 继续添加依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>2.2.0.RELEASE</version>
</dependency>
- 在网关的soul-bootstrap --> application-local.yml文件中 新增如下配置
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/ # 你的eureka地址
instance:
prefer-ip-address: true
2、soul-examples --> soul-examples-springcloud 服务
- 添加如下依赖:
<dependency>
<groupId>org.dromara</groupId>
<artifactId>soul-spring-boot-starter-client-springcloud</artifactId>
<version>${soul.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>${spring-cloud.version}</version>
</dependency>
- soul-examples-springcloud --> application.yml
eureka:
client:
serviceUrl:
defaultZone:http://localhost:8761/eureka/
soul:
springcloud:
admin-url:http://localhost:9095
context-path:/springcloud
3、soul-admin 插件设置
soul-admin --> 插件管理 --> springCloud,设置为开启。
二、启动服务
- soul-examples --> soul-examples-eureka 启动 eureka注册中心
- soul-bootstrap 启动网关服务
- soul-examples --> soul-examples-springcloud 启动 springcloud 服务
soul-examples --> soul-examples-springcloud 服务接口注册到网关打印的成功信息
2021-01-19 15:37:58.304 INFO 82962 --- [pool-1-thread-1] o.d.s.client.common.utils.RegisterUtils : springCloud client register success: {"appName":"springCloud-test","context":"/springcloud","path":"/springcloud/order/path/**","pathDesc":"","rpcType":"springCloud","ruleName":"/springcloud/order/path/**","enabled":true}
2021-01-19 15:37:58.322 INFO 82962 --- [pool-1-thread-1] o.d.s.client.common.utils.RegisterUtils : springCloud client register success: {"appName":"springCloud-test","context":"/springcloud","path":"/springcloud/order/path/**/name","pathDesc":"","rpcType":"springCloud","ruleName":"/springcloud/order/path/**/name","enabled":true}
查看 soul-admin 接口注册信息
三、测试
通过网关请求 springcloud 接口,请求成功
未完待续
标签:网关,springCloud,springcloud,Soul,eureka,源码,examples,soul,cloud 来源: https://blog.csdn.net/liquan961646757/article/details/112854146