get service instances by Flux.blockLast() to resolve concurrent problem (#763)

pull/767/head
lepdou 2 years ago committed by GitHub
parent 2a67279fec
commit 1fcfd5b9b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -14,3 +14,4 @@
- [fix:fix discovery junit.](https://github.com/Tencent/spring-cloud-tencent/pull/728)
- [adapt polaris-java 1.10.1 version](https://github.com/Tencent/spring-cloud-tencent/pull/748)
- [Optimize: change RouteArgument.buildCustom to RouteArgument.fromLabel](https://github.com/Tencent/spring-cloud-tencent/pull/750)
- [Bugfix: get service instances by Flux.blockLast() to resolve concurrent problem](https://github.com/Tencent/spring-cloud-tencent/pull/763)

@ -0,0 +1,5 @@
# Change Log
---
- [fix:fix transfer http headers not working bug.](https://github.com/Tencent/spring-cloud-tencent/pull/665)
- [Bugfix: get service instances by Flux.blockLast() to resolve concurrent problem](https://github.com/Tencent/spring-cloud-tencent/pull/762)

@ -18,10 +18,8 @@
package com.tencent.cloud.polaris.loadbalancer;
import java.util.Collections;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import com.tencent.cloud.common.metadata.MetadataContext;
import com.tencent.cloud.common.pojo.PolarisServiceInstance;
@ -54,19 +52,22 @@ public final class LoadBalancerUtils {
* @return ServiceInstances
*/
public static ServiceInstances transferServersToServiceInstances(Flux<List<ServiceInstance>> servers) {
AtomicReference<List<Instance>> instances = new AtomicReference<>();
servers.subscribe(serviceInstances -> instances.set(serviceInstances.stream()
.map(LoadBalancerUtils::transferServerToServiceInstance)
.collect(Collectors.toList())));
String serviceName = null;
if (CollectionUtils.isEmpty(instances.get())) {
instances.set(Collections.emptyList());
List<ServiceInstance> serviceInstances = servers.blockLast();
List<Instance> instances = new ArrayList<>();
if (!CollectionUtils.isEmpty(serviceInstances)) {
for (ServiceInstance serviceInstance : serviceInstances) {
instances.add(transferServerToServiceInstance(serviceInstance));
}
}
else {
serviceName = instances.get().get(0).getService();
String serviceName = null;
if (!CollectionUtils.isEmpty(instances)) {
serviceName = instances.get(0).getService();
}
ServiceKey serviceKey = new ServiceKey(MetadataContext.LOCAL_NAMESPACE, serviceName);
return new DefaultServiceInstances(serviceKey, instances.get());
return new DefaultServiceInstances(serviceKey, instances);
}
/**

Loading…
Cancel
Save