Spring Cloud笔记2
1.在使用Feign的时候第一次请求总是time-out的问题
Feign整合了hystrix, 由于我们第一次请求的时候超过了1秒,所以才会报异常
解决方案:
解决第一次请求报超时异常的方案:
#hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 5000
或者:
hystrix.command.default.execution.timeout.enabled: false
或者:
feign.hystrix.enabled: false ## 索性禁用feign的hystrix支持
超时的issue:https://github.com/spring-cloud/spring-cloud-netflix/issues/768
超时的解决方案: http://stackoverflow.com/questions/27375557/hystrix-command-fails-with-timed-out-and-no-fallback-available
hystrix配置: https://github.com/Netflix/Hystrix/wiki/Configuration#execution.isolation.thread.timeoutInMilliseconds
2.peer高可用模式
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:111) ~[eureka-client-1.4.12.jar:1.4.12]
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56) ~[eureka-client-1.4.12.jar:1.4.12]
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$1.execute(EurekaHttpClientDecorator.java:59) ~[eureka-client-1.4.12.jar:1.4.12]
原因&解决方法:没有配置hostname
而且这里我加了这个依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
它会生成一个随机的密码,账号还是user
也可以把依赖删除
3
4.如何解决Eureka Server不踢出已关停的节点的问题?
server端:
eureka.server.enable-self-preservation (设为false,关闭自我保护主要)
eureka.server.eviction-interval-timer-in-ms 清理间隔(单位毫秒,默认是60*1000)
client端:
eureka.client.healthcheck.enabled = true 开启健康检查(需要spring-boot-starter-actuator依赖)
eureka.instance.lease-renewal-interval-in-seconds =10 租期更新时间间隔(默认30秒)
eureka.instance.lease-expiration-duration-in-seconds =30 租期到期时间(默认90秒)
示例:
服务器端配置:
eureka:
server:
enableSelfPreservation: false
evictionIntervalTimerInMs: 4000
客户端配置:
eureka:
instance:
leaseRenewalIntervalInSeconds: 10
leaseExpirationDurationInSeconds: 30
注意:
更改Eureka更新频率将打破服务器的自我保护功能
https://github.com/spring-cloud/spring-cloud-netflix/issues/373
5.Eureka Environment的配置:
eureka.environment: 字符串
参考文档:
https://github.com/Netflix/eureka/wiki/Configuring-Eureka
6.Eureka DataCenter的配置
eureka.datacenter: cloud
https://github.com/Netflix/eureka/wiki/Configuring-Eureka
这边说:配置-Deureka.datacenter=cloud,这样eureka将会知道是在AWS云上
7.ribbo
- 自定义配置时,@Configuration和@ComponentScan包不应重叠
- 使用RestTemplate时,想要获得一个List时,应该用数组,而不应该直接用List
8.feign
- 自定义配置时,@Configuration和@ComponentScan包不应重叠
- @FeignClient所在的接口中,不支持@GetMapping等组合注解
- 使用@PathVariable时,需要指定其value
- Feign暂不支持复杂对象作为一个参数
时间紧,任务重。加油!