当前位置:   article > 正文

eureka参数配置_evictionintervaltimerinms

evictionintervaltimerinms

最近自己开始研究下微服务,总结下服务注册中心

主要是服务经常会超时,或者访问不了,跟服务注册中心配置有关系的。

注册服务中心

application.properties

  1. spring.application.name=eureka
  2. server.port=10001
  3. #强制不rver.port注册到注册服务器
  4. eureka.client.register-with-eureka=false
  5. eureka.client.fetch-registry=false
  6. #eureka.instance.hostname=localhost
  7. #注册中心地址
  8. eureka.client.serviceUrl.defaultZone=http://localhost:${server.port}/eureka/
  9. #驱逐下线的服务,间隔,5秒,默认是60,建议开发和测试环境配置
  10. #org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean.evictionIntervalTimerInMs
  11. #eureka.server.evictionIntervalTimerInMs=60000
  12. #关闭eureka自我保护机制,修改检查失效服务的时间
  13. eureka.server.enable-self-preservation=false
  14. eureka.server.eviction-interval-timer-in-ms=10000
  15. #减少心跳时间
  16. #eureka.instance.lease-expiration-duration-in-seconds=90
  17. #eureka.instance.lease-renewal-interval-in-seconds=4
  18. #忽略权限拦截
  19. management.security.enabled=false

Eureka Client

application.properties

  1. server.port=8082
  2. #root日志以WARN级别输出
  3. logging.level.root=INFO
  4. #springframework.web日志以DEBUG级别输出
  5. logging.level.org.springframework.web=DEBUG
  6. eureka.client.serviceUrl.defaultZone = http://localhost:10001/eureka/
  7. spring.application.name = talk-service
  8. eureka.instance.lease-renewal-interval-in-seconds= 5
  9. # 心跳时间,即服务续约间隔时间(缺省为30s)
  10. eureka.instance.lease-expiration-duration-in-seconds= 5
  11. # 发呆时间,即服务续约到期时间(缺省为90s)
  12. #client.healthcheck.enabled=true
  13. ribbon.ReadTimeout=60000
  14. ribbon.ConnectTimeout=60000
  15. feign.hystrix.enabled=false
  16. eureka.instance.instance-id=${spring.cloud.client.ipAddress}:${server.port}
  17. eureka.instance.prefer-ip-address=true
  18. #eureka.instance.preferIpAddress=true
  19. #eureka.client.registry-fetch-interval-seconds=30

 

其次在Eureka重写服务状态的监听器

  1. package com.example.demo;
  2. import com.netflix.appinfo.InstanceInfo;
  3. import org.springframework.cloud.netflix.eureka.server.event.*;
  4. import org.springframework.context.event.EventListener;
  5. import org.springframework.stereotype.Component;
  6. /**
  7. * 服务上下线监控
  8. */
  9. @Component
  10. public class EurekaStateChangeListener {
  11. @EventListener
  12. public void listen(EurekaInstanceCanceledEvent event){
  13. System.err.println(event.getServerId()+"\t"+event.getAppName()+"服务下线");
  14. }
  15. @EventListener
  16. public void listen(EurekaInstanceRegisteredEvent event){
  17. InstanceInfo instanceInfo=event.getInstanceInfo();
  18. System.err.println(instanceInfo.getAppName()+"进行注册");
  19. }
  20. @EventListener
  21. public void listen(EurekaInstanceRenewedEvent event){
  22. System.err.println(event.getServerId()+"\t"+event.getAppName()+"服务进行续约");
  23. }
  24. @EventListener
  25. public void listen(EurekaRegistryAvailableEvent event){
  26. System.err.println("注册中心启动");
  27. }
  28. @EventListener
  29. public void listen(EurekaServerStartedEvent event){
  30. System.err.println("Eureka Server 启动");
  31. }
  32. }

 

输出如下

  1. 2018-12-05 00:02:14.614 INFO 1616 --- [io-10001-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 94 ms
  2. TALK-SERVICE进行注册
  3. 2018-12-05 00:02:16.236 INFO 1616 --- [io-10001-exec-2] c.n.e.registry.AbstractInstanceRegistry : Registered instance TALK-SERVICE/127.0.0.1:8082 with status UP (replication=false)
  4. TALK-SERVICE进行注册
  5. 2018-12-05 00:02:17.118 INFO 1616 --- [io-10001-exec-3] c.n.e.registry.AbstractInstanceRegistry : Registered instance TALK-SERVICE/127.0.0.1:8082 with status UP (replication=true)
  6. 127.0.0.1:8082 TALK-SERVICE服务进行续约
  7. 127.0.0.1:8082 TALK-SERVICE服务进行续约
  8. 2018-12-05 00:02:24.554 INFO 1616 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry : Running the evict task with compensationTime 0ms
  9. 127.0.0.1:8082 TALK-SERVICE服务进行续约
  10. 127.0.0.1:8082 TALK-SERVICE服务进行续约
  11. 127.0.0.1:8082 TALK-SERVICE服务进行续约
  12. 127.0.0.1:8082 TALK-SERVICE服务进行续约
  13. 2018-12-05 00:02:34.555 INFO 1616 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry : Running the evict task with compensationTime 0ms
  14. 127.0.0.1:8082 TALK-SERVICE服务进行续约
  15. 127.0.0.1:8082 TALK-SERVICE服务进行续约
  16. 127.0.0.1:8082 TALK-SERVICE服务进行续约
  17. 127.0.0.1:8082 TALK-SERVICE服务进行续约
  18. 2018-12-05 00:02:44.555 INFO 1616 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry : Running the evict task with compensationTime 0ms
  19. 127.0.0.1:8082 TALK-SERVICE服务进行续约
  20. 127.0.0.1:8082 TALK-SERVICE服务进行续约
  21. 2018-12-05 00:02:54.555 INFO 1616 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry : Running the evict task with compensationTime 0ms
  22. 2018-12-05 00:03:04.555 INFO 1616 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry : Running the evict task with compensationTime 0ms
  23. 2018-12-05 00:03:04.555 INFO 1616 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry : Evicting 1 items (expired=1, evictionLimit=1)
  24. 2018-12-05 00:03:04.556 WARN 1616 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry : DS: Registry: expired lease for TALK-SERVICE/127.0.0.1:8082
  25. 127.0.0.1:8082 TALK-SERVICE服务下线

参数配置具体参考网络,这里提供大概的配置参数

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/码创造者/article/detail/955812
推荐阅读
相关标签
  

闽ICP备14008679号