springcloud-zuul-gateway
pom文件新增依赖:
<!--SpringCloud 整合 config-client--><dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
</dependency>
<!--actuator监控核心-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
批改application.yml配置文件:
## api网关端口号
server:
port: 80
## 服务注册名称
spring:
application:
name: server-zuul
cloud:
config:
#### 读取版本环境
profile: dev
discovery:
#### config server 服务注册别名
service-id: config-server
#### 开启读取权限
enabled: true
eureka:
client:
service-url:
##以后服务注册到Eureka服务地址
defaultZone: http://localhost:8100/eureka,http://localhost:9100/eureka
register-with-eureka: true
## 须要检索服务信息
fetch-registry: true
#### 配置动静
#zuul:
# routes:
# ## 示意定义转发服务规定
# api-a:
# ### 当客户端发送申请http://127.0.0.1:80/api-member结尾的,都会转发到会员服务
# path: /api-member/**
# ### 会员服务别名 zuul默认整合ribbon,主动实现轮询成果
# serviceId: app-member
# api-b:
# ### 当客户端发送申请http://127.0.0.1:80/api-order结尾的,都会转发到订单服务
# path: /api-order/**
# ### 订单服务别名 zuul默认整合ribbon,主动实现轮询成果
# serviceId: app-order
####开启所有端点
management:
endpoints:
web:
exposure:
include: "*"
正文掉的局部,新增yml文件到Getee上
AppGateway启动类新增zuul配置
package com.baba.wlb;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
/**
* @Author wulongbo
* @Date 2021/1/28 11:52
* @Version 1.0
*/@SpringBootApplication
@EnableEurekaClient
@EnableZuulProxy
public class AppGateway {
//@EnableZuulProxy 开启网关代理
public static void main(String[] args) {
SpringApplication.run(AppGateway.class, args);
}
// zuul配置可能应用config实现施行更新
@RefreshScope
@ConfigurationProperties("zuul")
public ZuulProperties zuulProperties(){
return new ZuulProperties();
}
}
启动我的项目
顺次启动Eureka Server、Config Server、Zuul网关gateway,以及Member 或者 Order服务
Config Server服务
分布式配置核心 config server验证gitee上的配置文件可能正确读取,拜访:http://localhost:8888/server-zuul-dev.yml
网关拜访
zuul网关拜访:http://localhost/api-member/getMember?name=iswulongbo&userToken=cloud
验证动静读取到了gitee上的配置文件,要动静批改或者动静新增服务到zuul网关,只需在gitee的配置文件中增加完后手动调用接口刷新或者通过集成bus音讯总线就OK!这里不再阐明。
发表回复