springcloud Ribbon自定义负载均衡插件
现在我们通过插件的方式添加新的一种策略。
package com.zhuyang.config; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean; import com.netflix.client.config.IClientConfig;
import com.netflix.loadbalancer.IPing;
import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.PingUrl;
import com.netflix.loadbalancer.RandomRule; /**
*
* Here, we override the IPing and IRule used by the default load balancer. The
* default IPing is a NoOpPing (which doesn’t actually ping server instances,
* instead always reporting that they’re stable), and the default IRule is a
* ZoneAvoidanceRule (which avoids the Amazon EC2 zone that has the most
* malfunctioning servers, and might thus be a bit difficult to try out in our
* local environment).
*
*/
@Configuration
public class RibbonConfiguration {
@Bean
public IClientConfig ribbonPing(){
IClientConfig config = new DefaultClientConfigImpl();
return config;
} @Bean
public IRule ribbonRule(IClientConfig config) { return new MyRule();
}
}
MyRule.java是自己定义的个算法,大概算法是随机选中能被2整除的server
这样我们自己写的策略算法就可以正常工作了。 所有的请求都只会到8003或者8000折两台server去。
springcloud Ribbon自定义负载均衡插件的更多相关文章
- SpringCloud的Ribbon自定义负载均衡算法
1.Ribbon默认使用RoundRobinRule策略轮询选择server 策略名 策略声明 策略描述 实现说明 BestAvailableRule public class BestAvailab ...
- Ribbon自定义负载均衡策略,在网关实现类似Ip_hash的负载均衡,ribbon给单个服务配置属性
背景: 我需要在网关实现一种功能,某个用户的请求永远打在后台指定的服务,也就是根据ip地址进行负载均衡 原理: 在ribbon的配置类下: 那我们自己创建一个IRule的实现类,模仿ZoneAvoid ...
- springcloud ribbon 客户端负载均衡用法
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is ...
- Spring Cloud Gateway Ribbon 自定义负载均衡
在微服务开发中,使用Spring Cloud Gateway做为服务的网关,网关后面启动N个业务服务.但是有这样一个需求,同一个用户的操作,有时候需要保证顺序性,如果使用默认负载均衡策略,同一个用户的 ...
- Srping cloud Ribbon 自定义负载均衡
IRule 默认提供有7种方式,使用轮询方式 如何自定义 1:主启动类加@RibbonClient @RibbonClient(name="微服务名", configuration ...
- Spring-Cloud-Ribbon学习笔记(二):自定义负载均衡规则
Ribbon自定义负载均衡策略有两种方式,一是JavaConfig,一是通过配置文件(yml或properties文件). 需求 假设我有包含A和B服务在内的多个微服务,它们均注册在一个Eureka上 ...
- SpringCloud全家桶学习之客户端负载均衡及自定义负载均衡算法----Ribbon(三)
一.Ribbon是什么? Spring Cloud Ribbon是基于Netflix Ribbon实现的一套客户端 负载均衡的工具(这里区别于nginx的负载均衡).简单来说,Ribbon是Netf ...
- SpringCloud Netflix Ribbon(负载均衡)
⒈Ribbon是什么? Spring Cloud Ribbon是基于Netflix Ribbon实现的一套客户端负载均衡工具. Ribbon是Netflix发布的开源项目,主要功能是提供客户端的软件负 ...
- java框架之SpringCloud(4)-Ribbon&Feign负载均衡
在上一章节已经学习了 Eureka 的使用,SpringCloud 也提供了基于 Eureka 负载均衡的两种方案:Ribbon 和 Feign. Ribbon负载均衡 介绍 SpringCloud ...
随机推荐
- Solr打分出错
solr支持给某Field打分,在验证的过程的过程中出现错误:ERROR: [doc=likehua] cannot set an index-time boost, unindexed or nor ...
- C#应用视频教程3.4 Halcon+C#测试
有了前面的基础后,我们来测试一下如何把程序做的更通用,首先是把初始化的方法修改一下,在初始化的时候传递过去HTuple这个对象(改成了全局的变量,以便于不同的方法调用) 其次需要有相机打开/相机关 ...
- 如何安装Tomcat
1 请确认已经安装了JRE或JDK并配置好了环境变量,关于如何配置环境变量,参考我的另一篇文章"WIN7如何配置java环境变量,运行环境.doc" 2 用记事本打开bin目录下的 ...
- ios8 xcode6 下的启动界面设置和图标设置
IOS8 我试了网上不少设置启动动画的,不知道是不是我弄错了还是怎么的,反正启动不了,后来在code4论坛找到了这个: 启动屏幕:LaunchScreen.xib文件 桌面图标等相关app图片:Ima ...
- php之快速入门学习-18(PHP 面向对象)
PHP 面向对象 在面向对象的程序设计(英语:Object-oriented programming,缩写:OOP)中,对象是一个由信息及对信息进行处理的描述所组成的整体,是对现实世界的抽象. 在现实 ...
- mv命令(转)
原文:http://www.cnblogs.com/peida/archive/2012/10/27/2743022.html mv命令是move的缩写,可以用来移动文件或者将文件改名(move (r ...
- windows下npm默认的全局路径
C:\Users\用户名\AppData\Roaming\npm\node_modules
- Nhibernate Criteria 多个or条件查询
sql: select * from table t where (t.name like '%张三%' or t.schoolName like '%张三%' or t.cityname like ...
- red5源代码编译并打包公布
编译环境:ubuntu14.04/JDK7 步骤: 1.svn检出源代码(两种方式) svn co --depth empty https://github.com/Red5/red5-server ...
- JavaWeb 路径问题
路径问题 CreateTime--2016年9月22日15:19:56 Author:Marydon 一.jsp页面 src="../demo/clazz/clazz_add.js&qu ...