本项目是搭建基于eureka注册中心的springcloud,使用zuul网关和gateway网关
一、框架搭建
(1)项目结构
eureka-server eureka注册中心
micro-service 服务提供者
zuul-gateway zuul网关
springcloud-gateway gateway网关
(2)环境
eureka-server 2.1.3
springboot 2.1.9
springcloud Greenwich
二、项目配置application.yaml
localhost:8180为本地eureka单点注册注册中心地址
(1)eureka-server
spring:application:name: eureka-serverprofiles:active: devjackson:time-zone: GMT+8date-format: yyyy-MM-dd HH:mm:ssdefault-property-inclusion: ALWAYScloud:config:enabled: falseeureka:server:#enableSelfPreservation: false #自我保存模式renewalPercentThreshold: 0 #续订阈值client:fetch-registry: falseregister-with-eureka: false
# service-url:
# defaultZone: http://localhost:${server.port}/eurekaserver:port: 8180
(2)micro-service
spring:application:name: micro-serviceprofiles:active: devjackson:time-zone: GMT+8date-format: yyyy-MM-dd HH:mm:ssdefault-property-inclusion: ALWAYSeureka:client:service-url:defaultZone: http://localhost:8180/eurekaserver:port: 8081
(3)zuul-gateway
spring:application:name: zuul-gatewayprofiles:active: devjackson:time-zone: GMT+8date-format: yyyy-MM-dd HH:mm:ssdefault-property-inclusion: ALWAYSeureka:client:service-url:defaultZone: http://localhost:8180/eurekaserver:port: 8082zuul:strip-prefix: true #转发路径截断匹配前缀
# prefix: "/api"add-proxy-headers: falseset-content-length: truesemaphore:max-semaphores: 600hystrix:command:default:execution:isolation:thread:timeoutInMilliseconds: 120000
ribbon:ReadTimeout: 240000ConnectTimeout: 2000MaxAutoRetries: 0MaxAutoRetriesNextServer: 1eager-load:enabled: trueclients: micro-service
(4)springcloud-gateway
spring:application:name: springcloud-gatewayprofiles:active: devjackson:time-zone: GMT+8date-format: yyyy-MM-dd HH:mm:ssdefault-property-inclusion: ALWAYScloud:gateway:discovery:locator:enabled: truelower-case-service-id: truehttpclient:connect-timeout: 60000response-timeout: 5sroutes:- id: micro-service1uri: lb://micro-servicepredicates:- Path=/micro-service1/**filters:- StripPrefix=1- id: micro-service3uri: lb://micro-servicepredicates:- Path=/micro-service3/**filters:- PrefixPath=/microeureka:client:service-url:defaultZone: http://localhost:8180/eurekaserver:port: 8083hystrix:command:default:execution:isolation:thread:timeoutInMilliseconds: 120000
ribbon:ReadTimeout: 240000ConnectTimeout: 2000MaxAutoRetries: 0MaxAutoRetriesNextServer: 1eager-load:enabled: trueclients: micro-service
三、项目地址
https://github.com/90duc/springcloud-eureka