一、Eureka

1.1、Eureka Environment的配置:

eureka.environment: 字符串

参考文档:

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

1.2. Eureka DataCenter的配置

eureka.datacenter: cloud

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

这边说:配置-Deureka.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 Server之间存在网络分区场景下的保护。一旦进入保护模式,Eureka Server将会尝试保护其服务注册表中的信息,不再删除服务注册表中的数据(也就是不会注销任何微服务)。

https://github.com/Netflix/eureka/wiki/Understanding-Eureka-Peer-to-Peer-Communication

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

eureka.instance.leaseRenewalIntervalInSeconds

参考文档:

http://cloud.spring.io/spring-cloud-static/Camden.SR1/#_why_is_it_so_slow_to_register_a_service

原文:

Why is it so Slow to Register a Service?

Being an instance also involves a periodic heartbeat to the registry (via the client’s serviceUrl) with default duration 30 seconds. A service is not available for discovery by clients until the instance, the server and the client all have the same metadata in their local cache (so it could take 3 heartbeats). You can change the period using eureka.instance.leaseRenewalIntervalInSeconds and this will speed up the process of getting clients connected to other services. In production it’s probably better to stick with the default because there are some computations internally in the server that make assumptions about the lease renewal period.

翻译:

作为实例还涉及到与注册中心的周期性心跳,默认持续时间为30秒(通过serviceUrl)。在实例、服务器、客户端都在本地缓存中具有相同的元数据之前,服务不可用于客户端发现(所以可能需要3次心跳)。你可以使用eureka.instance.leaseRenewalIntervalInSeconds 配置,这将加快客户端连接到其他服务的过程。在生产中,最好坚持使用默认值,因为在服务器内部有一些计算,他们对续约做出假设。

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

单例STS下,正常退出是可以剔除的,如果强制关闭,是不剔除的

集群下,

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

1.6. Eureka配置instanceId显示IP

在Spring Cloud中,服务的Instance ID的默认值是${spring.cloud.client.hostname}:${spring.application.name}:${spring.application.instance_id:${server.port}} ,也就是机器主机名:应用名称:应用端口 。因此在Eureka Server首页中看到的服务的信息类似如下:itmuch:microservice-provider-user:8000 。如果想要自定义这部分的信息怎么办?

eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
instance:
preferIpAddress: true
instance-id: ${spring.cloud.client.ipAddress}:${server.port}

1.7. Eureka配置最佳实践总结

https://github.com/spring-cloud/spring-cloud-netflix/issues/203

二、Ribbon

2.1. 自定义配置时,@Configuration和@ComponentScan包不应重叠

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

        // wrong
// List<User> list = restTemplate.getForObject("http://microservice-provider-user/list-all",List.class);
// for (User u : list) {
// System.out.println(u);
// }
// right
User[] users = restTemplate.getForObject("http://microservice-provider-user/list-all", User[].class);
List<User> list2 = Arrays.asList(users);
return list2;

三、 Feign

3.1. 自定义配置时,@Configuration和@ComponentScan包不应重叠

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

3.3. 使用@PathVariable时,需要指定其value

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

0409-服务注册与发现-Eurek Ribbon Feign常见问题及解决的更多相关文章

  1. SpringCloud之服务注册与发现Eureka+客户端Feign

    前言 SpringCloud 是微服务中的翘楚,最佳的落地方案. Eureka 作为注册中心,是 SpringCloud 体系中最重要最核心的组件之一. Feign 使用接口加注解的方式调用服务,配合 ...

  2. Spring Cloud Consul 实现服务注册和发现

    Spring Cloud 是一个基于 Spring Boot 实现的云应用开发工具,它为基于 JVM 的云应用开发中涉及的配置管理.服务发现.断路器.智能路由.微代理.控制总线.全局锁.决策竞选.分布 ...

  3. .NET Core微服务之基于Steeltoe使用Eureka实现服务注册与发现

    Tip: 此篇已加入.NET Core微服务基础系列文章索引 =>  Steeltoe目录快速导航: 1. 基于Steeltoe使用Spring Cloud Eureka 2. 基于Steelt ...

  4. Spring Cloud 系列之 Eureka 实现服务注册与发现

    如果你对 Spring Cloud 体系还不是很了解,可以先读一下 Spring Cloud 都有哪些模块 Eureka 是 Netflix 开源的服务注册发现组件,服务发现可以说是微服务架构的核心功 ...

  5. Spring Cloud Eureka 实现服务注册与发现

    微服务 是一种架构模式,跟具体的语言实现无关,微服务架构将业务逻辑分散到了各个服务当中,服务间通过网络层进行通信共同协作:这样一个应用就可以划分为多个服务单独来维护发布.构建一个可靠微服务系统是需要具 ...

  6. 白话SpringCloud | 第三章:服务注册与发现(Eureka)-下

    前言 上一章节,讲解了在单机模式下的服务注册与发现的相关知识点及简单示例.而在实际生产或者在这种微服务架构的分布式环境中,需要考虑发生故障时,各组件的高可用.而其实高可用,我的简单粗俗理解就是,通过系 ...

  7. Spring Cloud Alibaba(一) 如何使用nacos服务注册和发现

    Nacos介绍 Nacos 致力于帮助您发现.配置和管理微服务.Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现.服务配置.服务元数据及流量管理. Nacos 帮助您更敏捷和容易地构 ...

  8. SpringCloud的入门学习之概念理解、Eureka服务注册与发现入门

    1.微服务与微服务架构.微服务概念如下所示: 答:微服务强调的是服务的大小,它关注的是某一个点,是具体解决某一个问题.提供落地对应服务的一个服务应用,狭意的看,可以看作Eclipse里面的一个个微服务 ...

  9. springcloud(二):Eureka服务注册与发现

    Spring Cloud Netflix  该项目是Spring Cloud的子项目之一,主要内容是对Netflix公司一系列开源产品的包装,它为Spring Boot应用提供了自配置的Netflix ...

随机推荐

  1. PHP学习笔记(1)数组函数

    1.数组的键值操作函数: $arr = array("小明" => 98, "小红" => 76, "小黑" => 66, ...

  2. centos单机安装Hadoop2.6

    一,安装环境 硬件:虚拟机 操作系统:Centos 6.4 64位 IP:10.51.121.10 主机名:datanode-4 安装用户:root 二,安装JDK 安装JDK1.6或者以上版本.这里 ...

  3. 最纯粹的直播技术实战02-Camera的处理以及推流

    最纯粹的直播技术实战02-Camera的处理以及推流 最新实战教程.Android自己主动化刷量.作弊与防作弊.案例:刷友盟统计.批量注冊苹果帐号 这个系列的文章将会研究最纯粹的Android直播的实 ...

  4. dd & cpio

    dd: ------------------------------------------------------ - 指定大小块的拷贝一个文件 例1. 想把软盘的内容拷贝到另一个软盘   dd i ...

  5. Jafka Broker代码阅读之总览

    从本文开始,笔者将尝试从源码角度解读Jafka(Kafka)的特性,探究其背后的实现原理与技术.前面讲解Jafka Broker的文章中有提到下面这段启动服务端的代码,我们就从这里开始. Proper ...

  6. CSS中的绝对定位(absolute)误区

    这几天在慕课上看视频学习,偶然听到几个老师都说:CSS绝对定位在没有其他有除static定位的包含块的情况下是以body进行定位,如果要想相对当前元素的父元素来定位,父元素一定要设置position: ...

  7. jqgrid的排序问题

    今天是本人解决的一个小bug  所以写的粗略些. 问题是这样的ORDER BY  a.$sidx $sord 当时本人排序时候没用jqgrid的默认排序(可能今天这个大家看不懂,很抱歉啊各位,今天主要 ...

  8. hbase0.96.0单机模式安装(win7 无需cygwin)

        之前折腾了几天,想让hbase的单机模式在cygwin上跑起来,都不成功.正当我气馁之时,我无意中发现hbase0.96.0的bin和conf目录下有一些扩展名为cmd的文件.这难道是给win ...

  9. 第0步:OracleRAC软件准备

    表1   软件准备列表 安装包属性 文件信息 Oracle 11.2.0.4 p13390677_112040_Linux-x86-64_1of7.zip   p13390677_112040_Lin ...

  10. tomcat报错-----》Unable to open debugger port IDEA Unable to open debugger port

    原因:IDEA配置的端口被占用了 解决方法: 方法一: 查找idea配置的调试端口--查看占用该端口的进程--杀掉进程 方法二:查找idea配置的调试端口--修改调试端口(未被使用的) 基本步骤: 1 ...