1.注解配置

@RibbonClient(name = "xxx",configuration = XxxRibbonConfig.class)
public class XxxRibbonConfig { String listOfServers = "http://192.168.99.100:8080,http://192.168.99.101:8080"; @Bean
public ServerList<Server> ribbonServerList() {
List<Server> list = Lists.newArrayList();
if (!Strings.isNullOrEmpty(listOfServers)) {
for (String s: listOfServers.split(",")) {
list.add(new Server(s.trim()));
}
}
return new StaticServerList<Server>(list);
}
}

2.启动类配置

@SpringCloudApplication
@RibbonClients(value = {
@RibbonClient(name = "xxx",configuration = XxxRibbonConfig.class),
@RibbonClient(name = "demo",configuration = DemoRibbonConfig.class)
})
public class DemoServiceApplication { public static void main(String[] args) {
SpringApplication.run(DemoServiceApplication.class, args);
}
}

3.属性配置

service-hi:
ribbon:
ReadTimeout: 1000
SocketTimeout: 1000
ConnectTimeout: 1000
MaxAutoRetries: 0
MaxAutoRetriesNextServer: 1
eureka:
enabled: true

4.设置resttemplate的超时时间(这个超时时间不知道是否与熔断有关)

package com.client;

import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate; @Configuration
public class RibbonConf { @Bean
@LoadBalanced
public RestTemplate getRestTemplate(){
//return new RestTemplate(); SimpleClientHttpRequestFactory simpleClientHttpRequestFactory = new SimpleClientHttpRequestFactory();
simpleClientHttpRequestFactory.setConnectTimeout(10000);
simpleClientHttpRequestFactory.setReadTimeout(10000);
return new RestTemplate(simpleClientHttpRequestFactory); } }

Ribbon的配置的更多相关文章

  1. 【Ribbon篇四】Ribbon初步配置(2)

    一. 微服务消费者改造 注:修改microservicecloud-consumer-dept-80工程 1. pom.xml添加依赖 <!-- eureka client --> < ...

  2. 笔记:Spring Cloud Ribbon 客户端配置详解

    自动化配置 由于 Ribbon 中定义的每一个接口都有多种不同的策略实现,同时这些接口之间又有一定的依赖关系,Spring Cloud Ribbon 中的自动化配置能够很方便的自动化构建接口的具体实现 ...

  3. springcloud-04-自定义ribbon的配置方式

    在dubbo项目中, zookeeper即注册中心帮我们实现了调度和负载均衡的能力, 这种方式被称为服务器端的负载均衡, springcloud中, 使用ribben实现的客户端负载均衡 什么是rib ...

  4. Ribbon 常用配置

    配置参数 默认值 说明 <client>.<namespace>.listOfServers 配置服务器列表 <client>.<namespace>. ...

  5. feignClient中修改ribbon的配置

    1.使用@FeignClient注解发现服务 服务提供者的controller: @RestController public class StudentController { @Autowired ...

  6. 四(1)、springcloud之Ribbon初步配置

    1.概述 ​ Spring Cloud Ribbon是基于Netflix Ribbon实现的一套客户端 -负载均衡的工具.Ribbon是Netflix发布的开源项目,主要功能是提供客户端的软件负载均衡 ...

  7. Ribbon&OpenFeign配置使用

    目录 Ribbon 是什么 工作流程 怎么用 负载算法 官方提供算法 使用方法 自定义负载算法 在rule包下新建MyRule 修改自定义策略类RbRule 测试 OpenFeign 是什么 怎么用 ...

  8. SpringCloud系列五:Ribbon 负载均衡(Ribbon 基本使用、Ribbon 负载均衡、自定义 Ribbon 配置、禁用 Eureka 实现 Ribbon 调用)

    1.概念:Ribbon 负载均衡 2.具体内容 现在所有的服务已经通过了 Eureka 进行了注册,那么使用 Eureka 注册的目的是希望所有的服务都统一归属到 Eureka 之中进 行处理,但是现 ...

  9. 使用Java代码自定义Ribbon配置

    很多场景下,需要实现不同的微服务采用不同的策略,例如修改Ribbon的负载均衡规则等.Spring Cloud允许使用Java代码自定义Ribbon的配置. 在Spring Cloud中,Ribbon ...

随机推荐

  1. 关于"引用"的几点说明

    一.引用的基本知识 引用就是某一变量(目标)的一个别名,对引用的操作与对变量直接操作完全一样.引用的声明方法:类型标识符 &引用名=目标变量名: 说明: (1)&在此不是求地址运算,而 ...

  2. vue单文件(sfc)编译为js的流程

    1.流程 2.参考文章地址 https://segmentfault.com/a/1190000012336392 3.Vue框架的parseComponent https://github.com/ ...

  3. jquery position方法使用及兼容性

    1.position方法 jquery api地址:http://jquery.cuishifeng.cn/position.html position方法获取匹配元素相对父元素的偏移. 2.说明 2 ...

  4. java 如何查看jdk版本&位数

      java 如何查看jdk版本&位数 CreateTime--2018年4月22日18:20:18 Author:Marydon 方式一:通过dos命令实现 win+R-->cmd-- ...

  5. eclipse javaWeb项目如何引入jar包

      eclipse javaWeb项目如何引入jar包 CreateTime--2018年4月19日08:54:24 Author:Marydon 1.判断当前jar包是否已经引入到项目当中的3种方式 ...

  6. Linux内核3.11的socket busy poll机制避免睡眠切换

    Linux的网络协议栈很独立,上下通过两个接口分别和用户态以及设备相连.也能够看作是北向和南向接口...北向通过socket接口,南向通过qdisc接口(你能够觉得是上层的netdev queue,对 ...

  7. java手动加载jar

    @RequestMapping("/testJar") public @ResponseBody String exteriorJar(int ys, int csd,int jg ...

  8. DIV+CSS专题:十天学会DIV+CSS

    DIV+CSS专题:十天学会DIV+CSS,在网上看到的.感觉蛮好,推荐一下. 十天学会DIV+CSS(WEB标准)CHM格式文件下载 第十天 div+css网页标准布局实例教程(三) 第十天 div ...

  9. 【centos6.5 安装 node.js + npm】

    1.参考链接:http://www.jb51.net/article/116231.htm 2.下载的nodejs版本一定要是v0.12.10的(传送门:https://nodejs.org/en/b ...

  10. 动态计算UITableViewCell高度详解

    本文将介绍四种情况下UITableViewCell的计算方式,分别是: Auto Layout with UILabel in UITableViewCell Auto Layout with UIT ...