zoukankan      html  css  js  c++  java
  • Eureka、Ribbon、Feign常见问题及解决

    1、Eureka常见问

    1.1、Eureka Enviroment 的配置

    eureka.enviroment=product

      参考 https://github.com/Netflix/eureka/wiki/Configuring-Eureka

    1.2、Eureka Datacenter 的配置

    eureka.datacenter=cloud 

      配置eureka.datacenter=cloud,这样eureka就知道是在AWS云上

    1.3、Eureka 开启自我保护的提示

       

    EMERGENCY! EUREKA MAY BE INCORRECTLY CLAIMING INSTANCES ARE UP WHEN THEY'RE NOT.
    RENEWALS ARE LESSER THAN THRESHOLD AND HENCE THE INSTANCES ARE NOT BEING EXPIRED JUST TO BE SAFE.

      Eureka进入保护模式时,不会踢出已关闭的节点。

    1.4、Eureka 注册服务慢的问题如何解决?

    1.5、如何解决Eureka Server不踢出已关闭的节点的问题?

    Server端
      #关闭eureka的自我保护
      eureka.server.enable-self-preservation=false
      #清理间隔时间,单位为毫秒
      eureka.server.eviction-interval-timer-in-ms=0 Client端
      #开启健康检查(需要spring-boot-starter-actuator依赖)
      eureka.client.healthcheck.enabled=true
      #租期到期时间,默认90秒
      eureka.instance.lease-expiration-duration-in-seconds=30
      #租赁更新时间间隔,默认30,即30秒发送一次心跳
      eureka.instance.lease-renewal-interval-in-seconds=10

      注意:更改Eureka更新频率将打破服务器的自我保护能力,生产环境中一般不推荐修改。

    1.6、Eureka 配置instanceId显示IP

    eureka.client.serviceUrl.defaultZone=http://user:password@localhost:8761/eureka
    #设置注册ip
    eureka.instance.prefer-ip-address=true
    eureka.instance.instanceId=${spring.application.name}:${spring.cloud.client.ipAddress}:${spring.application.instance_id:${server.port}}

      

    2、Ribbon

    2.1、自定义配置时,@Configuration和@ComponentScan所在包不应该重叠

    2.2、使用RestTemplate时,想要获得一个List时,应该用数组,而不应该直接用List。

      在microservice-provider-user项目中添加如下代码,返回list

      @GetMapping("/list-all")
        public List<User> listAll(){
            List<User> list = new ArrayList<User>();
            User user = new User(1,"zahngsan");
            User user2 = new User(2,"zahngsan2");
            User user3 = new User(3,"zahngsan3");
            list.add(user);
            list.add(user2);
            list.add(user3);
            return list;
        }

    直接访问此项目,得到如下结果:

      

      在microservice-consumer-movie-ribbon-list项目中通过RestTemplate访问以上内容:

    @GetMapping("/list-all")
        public List<User> list() {
            List<User> list = this.template.getForObject("http://microservice-provider-user:7900/list-all", List.class);
            for(User u:list){
                System.out.println(u.getId());
            }
            return list;
        }

      报错:

    java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to com.wyl.microservicesimpleconsumemovie.entity.User

      可看出RestTemplate得到的是LinkedHashMap对象,不是List对象。则通过以下代码解析:

    User[] list = this.template.getForObject("http://microservice-provider-user:7900/list-all", User[].class);
    for(User u:list){
      System.out.println(u.getId());
    }

    3、Feign

    3.1、自定义配置时,@Configuration和@Component所在包不应该重叠

    3.2、@FeignClient所在的接口中,不支持@GetMapping等组合注解

    3.3、使用@PathVariable时,需要制定其value

    3.4、Feign暂时不支持复杂对象作为一个参数

  • 相关阅读:
    git 的常用命令(未完待补充)
    Mysql占用内存过高参数优化
    mysql安全基线设置
    redis安全基线设置
    centos7安全基线设置
    检查shell脚本
    redis安装和配置
    TIME_WAIT状态全是3306解决办法
    PHP message: PHP Fatal error: Allowed memory size of 134217728 bytes exhausted 错误
    tcp的三次握手和四次挥手(二)
  • 原文地址:https://www.cnblogs.com/studyDetail/p/7090150.html
Copyright © 2011-2022 走看看