|
1 | 1 | /*
|
2 | 2 |
|
3 |
| - * Copyright (C) 2020-2022 Huawei Technologies Co., Ltd. All rights reserved. |
4 |
| -
|
5 |
| - * Licensed under the Apache License, Version 2.0 (the "License"); |
6 |
| - * you may not use this file except in compliance with the License. |
7 |
| - * You may obtain a copy of the License at |
8 |
| - * |
9 |
| - * http://www.apache.org/licenses/LICENSE-2.0 |
10 |
| - * |
11 |
| - * Unless required by applicable law or agreed to in writing, software |
12 |
| - * distributed under the License is distributed on an "AS IS" BASIS, |
13 |
| - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 |
| - * See the License for the specific language governing permissions and |
15 |
| - * limitations under the License. |
16 |
| - */ |
| 3 | + * Copyright (C) 2020-2022 Huawei Technologies Co., Ltd. All rights reserved. |
| 4 | +
|
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
17 | 17 |
|
18 | 18 | package com.huaweicloud.servicecomb.discovery.ribbon;
|
19 | 19 |
|
20 | 20 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
21 |
| -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
22 | 21 | import org.springframework.cloud.client.discovery.DiscoveryClient;
|
23 | 22 | import org.springframework.context.annotation.Bean;
|
24 | 23 | import org.springframework.context.annotation.Configuration;
|
25 | 24 |
|
26 | 25 | import com.huaweicloud.servicecomb.discovery.registry.ServiceCombRegistration;
|
27 | 26 | import com.netflix.client.config.IClientConfig;
|
28 |
| -import com.netflix.loadbalancer.IPing; |
29 |
| -import com.netflix.loadbalancer.ServerList; |
30 |
| -import com.netflix.loadbalancer.ServerListUpdater; |
31 |
| - |
32 |
| -/** |
33 |
| - * @Author wangqijun |
34 |
| - * @Date 17:15 2019-07-11 |
35 |
| - **/ |
| 27 | +import com.netflix.loadbalancer.AbstractServerList; |
| 28 | +import com.netflix.loadbalancer.ILoadBalancer; |
| 29 | +import com.netflix.loadbalancer.IRule; |
| 30 | +import com.netflix.loadbalancer.Server; |
| 31 | + |
36 | 32 | @Configuration
|
37 | 33 | public class ServiceCombRibbonClientConfiguration {
|
38 | 34 | @Bean
|
39 | 35 | @ConditionalOnMissingBean
|
40 |
| - public ServerList<?> ribbonServerList(IClientConfig config, DiscoveryClient discoveryClient, |
| 36 | + public ILoadBalancer ribbonLoadBalancer( |
| 37 | + IRule rule, AbstractServerList<Server> serverList) { |
| 38 | + return new ServiceCombLoadBalancer(rule, serverList); |
| 39 | + } |
| 40 | + |
| 41 | + @Bean |
| 42 | + @ConditionalOnMissingBean |
| 43 | + public AbstractServerList<Server> ribbonServerList(IClientConfig config, DiscoveryClient discoveryClient, |
41 | 44 | ServiceCombRegistration serviceCombRegistration) {
|
42 | 45 | ServiceCombServerList serverList = new ServiceCombServerList(discoveryClient, serviceCombRegistration);
|
43 | 46 | serverList.initWithNiwsConfig(config);
|
44 | 47 | return serverList;
|
45 | 48 | }
|
46 | 49 |
|
47 | 50 | @Bean
|
48 |
| - @ConditionalOnProperty(value = "spring.cloud.servicecomb.discovery.ping") |
49 |
| - public IPing ping() { |
50 |
| - return new ServiceCombIPing(); |
51 |
| - } |
52 |
| - |
53 |
| - @Bean |
54 |
| - public ServerListUpdater serviceCombServerListUpdater() { |
55 |
| - return new ServiceCombServerListUpdater(); |
| 51 | + @ConditionalOnMissingBean |
| 52 | + public IRule ribbonRule() { |
| 53 | + return new ServiceCombRoundRobinRule(); |
56 | 54 | }
|
57 | 55 | }
|
0 commit comments