zm
2020-05-18 a18bfacbf56b401f6e0fdae8710fbca4df8cff77
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package com.changhong.epc.zuul.config;
 
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Arrays;
 
import org.bouncycastle.crypto.tls.URLAndHash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.http.MediaType;
import org.springframework.web.client.RestTemplate;
 
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter4;
import com.iemsoft.framework.cloud.zuul.config.ZuulHystrixConfig;
import com.netflix.loadbalancer.BestAvailableRule;
import com.netflix.loadbalancer.IPing;
import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.PingUrl;
 
@Configuration
public class RibbonConfiguration extends ZuulHystrixConfig{
    
    /**
     * ping中心
     * @return
     */
    @Bean
    public IPing ribbonPing() {
        return new PingUrl(false, "/info.json");
    }
    
    /**
     * 
     * @return
     */
    @Bean
    @Scope("prototype")
    public IRule ribbonRule() {
//        return new BestAvailableRule(); //閫夋嫨涓�涓渶灏忕殑骞跺彂璇锋眰鐨剆erver
//        return new WeightedResponseTimeRule(); //鏍规嵁鐩稿簲鏃堕棿鍒嗛厤涓�涓獁eight锛岀浉搴旀椂闂磋秺闀匡紝weight瓒婂皬锛岃閫変腑鐨勫彲鑳芥�ц秺浣庛��
//        return new RetryRule(); //瀵归�夊畾鐨勮礋杞藉潎琛$瓥鐣ユ満涓婇噸璇曟満鍒躲��
//        return new RoundRobinRule(); //roundRobin鏂瑰紡杞閫夋嫨server
//        return new RandomRule(); //闅忔満閫夋嫨涓�涓猻erver
//        return new ZoneAvoidanceRule(); //澶嶅悎鍒ゆ柇server鎵�鍦ㄥ尯鍩熺殑鎬ц兘鍜宻erver鐨勫彲鐢ㄦ�ч�夋嫨server
        return new BestAvailableRule();
    }
    
}