All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.fashionbrot.ribbon.Test Maven / Gradle / Ivy

Go to download

mars-ribbon-api 负载均衡工具 https://github.com/fashionbrot/mars-dynamic-config

There is a newer version: 0.1.3
Show newest version
package com.github.fashionbrot.ribbon;

import com.github.fashionbrot.ribbon.enums.SchemeEnum;
import com.github.fashionbrot.ribbon.loadbalancer.BaseLoadBalancer;
import com.github.fashionbrot.ribbon.loadbalancer.ILoadBalancer;
import com.github.fashionbrot.ribbon.loadbalancer.Server;
import com.github.fashionbrot.ribbon.ping.PingUrl;
import com.github.fashionbrot.ribbon.rule.RandomRule;

import java.util.Arrays;

public class Test {

    public static void main(String[] args) {
        ILoadBalancer loadBalancer =new BaseLoadBalancer();
        loadBalancer.setRule(new RandomRule());
        loadBalancer.setPing(new PingUrl());
        loadBalancer.addServers(Arrays.asList(Server.builder().host("www.baidu.com").port(80).scheme(SchemeEnum.HTTP).build()
                ,Server.builder().host("blog.csdn.net").port(80).path("health").scheme(SchemeEnum.HTTP).build()));

        for (int i=0 ;i<100;i++) {
            Server server = loadBalancer.chooseServer();
            if (server==null){
                System.out.println("server is null");
            }else {
                System.out.println(server.toString() + "i:" + i);
            }
        }

    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy