搭建一个demo很简单但是要在生产线上用的配置还需要慎重考虑和布置某些属性的值,以下部署值仅供参考。
注册中心:
这个主要是 关注检查注册到注册中心的服务时间,这个会影响部署时候上线和下线 客户端的感知时间。感知时间是你自己项目的合理时间就好。这个配置适合中小型规模的项目
yml格式:
server:
port: 7002
spring:
application:
name: eureka1
eureka:
client:
serviceUrl:
defaultZone: http://localhost:7001/eureka/ (另一个注册中心的端口,搭建高可用)
server:
## 中小规模下,自我保护模式坑比好处多,所以关闭它
enableSelfPreservation: false
## 主动失效检测间隔,配置成5秒
evictionIntervalTimerInMs: 5000
## 禁用readOnlyCacheMap
useReadOnlyResponseCache: false
instance:
## 心跳间隔,5秒
leaseRenewalIntervalInSeconds: 5
## 没有心跳的淘汰时间,10秒
leaseExpirationDurationInSeconds: 10
网关zuul配置:
这个主要是网关请求时的超时时间,和请求数量最大值为 5000
server:
port: 8888
spring:
application:
name: gateway-service-zuul
eureka:
client:
serviceUrl:
defaultZone: http://localhost:7001/eureka/,http://localhost:7002/eureka/
zuul:
prefix: /appservice
host:
##url请求方式 超时时间设置
connection-timeout-millis: 10000
socket-timeout-millis: 60000
##最大请求量,默认为100
semaphore:
max-semaphores: 5000
##serverId请求方式 超时时间设置
ribbon:
ReadTimeout: 10000
SocketTimeout: 10000
服务端和消费端:
主要注意心跳时间和缓存的时间,这个也会影响上线和下线客户的感知时间
server:
port: 9003
spring:
application:
name: producer-2
eureka:
client:
serviceUrl:
defaultZone: http://localhost:7001/eureka/
registryFetchIntervalSeconds: 5 ## 定时刷新本地缓存时间
instance:
leaseRenewalIntervalInSeconds: 5 ## 心跳间隔,5秒
leaseExpirationDurationInSeconds: 10 ## 没有心跳的淘汰时间,10秒
ribbon:
ServerListRefreshInterval: 2000 ## ribbon缓存时间