现在我们通过插件的方式添加新的一种策略。

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自定义负载均衡插件的更多相关文章

  1. SpringCloud的Ribbon自定义负载均衡算法

    1.Ribbon默认使用RoundRobinRule策略轮询选择server 策略名 策略声明 策略描述 实现说明 BestAvailableRule public class BestAvailab ...

  2. Ribbon自定义负载均衡策略,在网关实现类似Ip_hash的负载均衡,ribbon给单个服务配置属性

    背景: 我需要在网关实现一种功能,某个用户的请求永远打在后台指定的服务,也就是根据ip地址进行负载均衡 原理: 在ribbon的配置类下: 那我们自己创建一个IRule的实现类,模仿ZoneAvoid ...

  3. springcloud ribbon 客户端负载均衡用法

    org.springframework.web.util.NestedServletException: Request processing failed; nested exception is ...

  4. Spring Cloud Gateway Ribbon 自定义负载均衡

    在微服务开发中,使用Spring Cloud Gateway做为服务的网关,网关后面启动N个业务服务.但是有这样一个需求,同一个用户的操作,有时候需要保证顺序性,如果使用默认负载均衡策略,同一个用户的 ...

  5. Srping cloud Ribbon 自定义负载均衡

    IRule 默认提供有7种方式,使用轮询方式 如何自定义 1:主启动类加@RibbonClient @RibbonClient(name="微服务名", configuration ...

  6. Spring-Cloud-Ribbon学习笔记(二):自定义负载均衡规则

    Ribbon自定义负载均衡策略有两种方式,一是JavaConfig,一是通过配置文件(yml或properties文件). 需求 假设我有包含A和B服务在内的多个微服务,它们均注册在一个Eureka上 ...

  7. SpringCloud全家桶学习之客户端负载均衡及自定义负载均衡算法----Ribbon(三)

    一.Ribbon是什么? Spring Cloud Ribbon是基于Netflix Ribbon实现的一套客户端  负载均衡的工具(这里区别于nginx的负载均衡).简单来说,Ribbon是Netf ...

  8. SpringCloud Netflix Ribbon(负载均衡)

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

  9. java框架之SpringCloud(4)-Ribbon&Feign负载均衡

    在上一章节已经学习了 Eureka 的使用,SpringCloud 也提供了基于 Eureka 负载均衡的两种方案:Ribbon 和 Feign. Ribbon负载均衡 介绍 SpringCloud ...

随机推荐

  1. C++中无法解析的外部符号错误

      在编译C++程序的时候,如果引用了对应的头文件,但是调用一个函数的时候仍然出现" 无法解析的外部符号错误"的编译错误,比如: 无法解析的外部符号__imp__PathFileE ...

  2. ArcGIS Pro体验01——申请、下载、安装

    ArcGIS Pro采用了Ribbon界面风格,看起来好漂亮,听起来很强大,就是不知道用起来怎么样,在网上看到一个ArcGIS Pro Beta2版本,下载下来,安装启动,好眼熟,像Office201 ...

  3. Java从零开始学三十五(JAVA IO- 字节流)

    一.字节流 FileOutputStream是OutputStream 的直接子类 FileInputStream也是InputStream的直接子类 二.文本文件的读写 2.1.字节输入流 Test ...

  4. 使用javacv录像,同时进行讯飞声纹认证

    由于最近的demo中需要在活体检测的同时进行音视频录制 ,  尝试使用MediaRecord和camera来录制视频 , 然而Camera.onPreviewFrame 不能与 MediaRecord ...

  5. cordova / Ionic 开发问题汇总

    cordova / Ionic 开发问题汇总 1. 导入工程的"The import android cannot be resolved"错误解决方法 2. MainActivi ...

  6. JVM中类的卸载机制

    类的生命周期 当Sample类被载入.连接和初始化后,它的生命周期就開始了. 当代表Sample类的Class对象不再被引用,即不可触及时,Class对象就会结束生命周期.Sample类在方法区内的数 ...

  7. spring的applicationContext.xml中的DBCP配置如下:

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy ...

  8. 【转】Asp.Net MVC4 之Url路由

    MVC4常见路由的处理方式 //直接方法重载+匿名对象 routes.MapRoute( name: "Default", url: "{controller}/{act ...

  9. 〖Linux〗build sqlite3 for Arm

    Version: sqlite-autoconf-3080100.tar.gz Download: https://www.sqlite.org/download.html 1. toolchains ...

  10. /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory 错误:

    在安装tomcat时报了错: /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory 本机环境: [root@AY1405 ...