• Ribbon Ping机制


    在负载均衡器中,提供了 Ping 机制,每隔一段时间,会去 Ping 服务器,判断服务器是否存活,该工作由 com.netflix.loadbalancer.IPing 接口的实现类负责,如果单独使用 Ribbon 默认情况下不会激活 Ping 机制,默认的实现类为 DummyPing(不验证),下面实现自定义的Ping 类,代码如下:

    package org.lixue.ribbon.client;

       

    import com.netflix.loadbalancer.IPing;

    import com.netflix.loadbalancer.Server;

       

    public class MyPing implements IPing{

    public boolean isAlive(Serverserver){

    System.out.println("isAlive"+server.getHostPort());

    return true;

    }

    }

    修改 src/main/resources 目录下的 ribbon-client.properties 配置如下:

    #配置服务器列表

    MyRibbonClient.ribbon.listOfServers=localhost:8080,localhost:8002

    #配置负载均衡规则IRule的实现类

    MyRibbonClient.ribbon.NFLoadBalancerRuleClassName=com.netflix.loadbalancer.WeightedResponseTimeRule

    #配置负载均衡实现类

    MyRibbonClient.ribbon.NFLoadBalancerClassName=com.netflix.loadbalancer.ZoneAwareLoadBalancer

    #配置IPing的实现类

    MyRibbonClient.ribbon.NFLoadBalancerPingClassName=org.lixue.ribbon.client.MyPing

    #配置Ping操作的间隔

    MyRibbonClient.ribbon.NFLoadBalancerPingInterval=2

       

    启动项目可以看到输出如下:

    isAlive localhost:8080

    isAlive localhost:8002

    request localhost:8002 active true

    request localhost:8080 active true

    request localhost:8002 active true

    request localhost:8080 active true

    request localhost:8002 active true

    request localhost:8080 active true

    request localhost:8002 active true

    request localhost:8080 active true

    request localhost:8002 active true

    request localhost:8080 active true

       

  • 相关阅读:
    flash模拟EEROM
    FATFS_SD卡
    AFIO
    ADC1多通道_DMA_内部温度传感器+内部VREFINT
    QmlBook--Meet Qt 5
    NRF24L01
    MWC飞控V2.3串口通信协议——new Multiwii Serial Protocol
    thread相关http://blog.csdn.net/forwayfarer/article/details/3455130
    comparable与comparator的区别http://blog.csdn.net/mageshuai/article/details/3849143
    ArrayList和LinkedList的区别http://pengcqu.iteye.com/blog/502676
  • 原文地址:https://www.cnblogs.com/li3807/p/8889612.html
Copyright © 2020-2023  润新知