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 ...
随机推荐
- [Sass] Level 3: Mixin -- Ex
When to use MIXIN? Better way to use MIXIN is when you deal with browser prefiex, for example: @mixi ...
- Asp.net 之页面处理积累(一)
1.实现超链接跳转网页直接定位到跳转后页面中部,而不是要往下拖,才能看到想看的内容 (1)在跳转后页面想定位的位置加:<a name="middle" id="mi ...
- C#中相关结构的用法及用途
C#中Dictionary的用法及用途 http://www.cnblogs.com/linzheng/archive/2010/12/13/1904709.html C#中的Dictionary字典 ...
- 使用第三方类、库需要注意的正则类RegexKitLite的使用
一.到http://regexkit.sourceforge.net/下载RegexKitLite类,添加到项目中: 因为RegexKitLite使用ICU库,所以需要动态链接到/usr/lib/li ...
- UISlider设置按钮透明
UISlider *aslider = [[UISlider alloc]initWithFrame:kCR(, , , )]; [aslider setValue:0.5]; [aslider se ...
- Linux 下搭建流媒体服务器
http://blog.csdn.net/huangtaishuai/article/details/9836581 ----------------------------------------- ...
- flume hdfs一些简单配置记忆
############################################ # producer config ##################################### ...
- java格式化百分比
NumberFormat nf = NumberFormat.getPercentInstance(); System.out.println(nf.format(0.47)); 显示:47% Dec ...
- git工具 将源码clone到本地指定目录的三种方式
git工具 将源码clone到本地指定目录的三种方式 CreationTime--2018年7月27日15点34分 Author:Marydon 1.情景展示 运行git-bash.exe,输入命 ...
- HighCharts画时间趋势图,标示区以及点击事件操作
最近在用HighCharts画趋势图,如果按照设计文档上来画那太复杂了,于是根据自己多年的经验改动了设计文档,添加了highcharts的标示区,然而我也发现,最后一次画highchart趋势图还是在 ...