catch webClient error
This commit is contained in:
@@ -11,6 +11,7 @@ import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -46,7 +47,8 @@ public class ApiService {
|
||||
public <T> Mono<List<T>> getInfoPakistan(GetInfoVO getInfoVO) {
|
||||
ParameterizedTypeReference<List<T>> typeRef = (ParameterizedTypeReference<List<T>>) tableObjectMapping.get(getInfoVO.getTableName());
|
||||
if (typeRef == null) {
|
||||
throw new IllegalArgumentException("不支持该表名: " + getInfoVO.getTableName());
|
||||
// throw new IllegalArgumentException("不支持该表名: " + getInfoVO.getTableName());
|
||||
return Mono.empty();
|
||||
}
|
||||
|
||||
return webClientBuilder
|
||||
@@ -58,7 +60,12 @@ public class ApiService {
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.bodyValue(getInfoVO)
|
||||
.retrieve()
|
||||
.bodyToMono(typeRef);
|
||||
.bodyToMono(typeRef)
|
||||
.onErrorResume(e -> {
|
||||
log.warn("WebClient 请求 eldData 失败,错误: {}", e.getMessage());
|
||||
return Mono.just(Collections.emptyList());
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// Pro API
|
||||
@@ -79,6 +86,10 @@ public class ApiService {
|
||||
.build())
|
||||
.header("eldKey", "435e833ca0610442d25b8011475c8352")
|
||||
.retrieve()
|
||||
.bodyToMono(typeRef);
|
||||
.bodyToMono(typeRef)
|
||||
.onErrorResume(e -> {
|
||||
log.warn("WebClient 请求 eldData 失败,错误: {}", e.getMessage());
|
||||
return Mono.just(Collections.emptyList());
|
||||
});
|
||||
}
|
||||
}
|
@@ -106,11 +106,11 @@ public class CompareService {
|
||||
List<String> valueFields = getValueField(tableName);
|
||||
|
||||
Map<String, Map<String, Object>> pakistanMap = pakistanList.stream()
|
||||
.collect(Collectors.toMap(item -> getValue(item, valueFields), item -> item,(existing, replacement) -> existing));
|
||||
.collect(Collectors.toMap(item -> getValue(item, valueFields), item -> item, (existing, replacement) -> existing));
|
||||
log.info("customerId = {} - tableName = {} - pakistanSet = {}", customerId, tableName, pakistanMap.keySet());
|
||||
|
||||
Map<String, Map<String, Object>> proMap = proList.stream()
|
||||
.collect(Collectors.toMap(item -> getValue(item, valueFields), item -> item,(existing, replacement) -> existing));
|
||||
.collect(Collectors.toMap(item -> getValue(item, valueFields), item -> item, (existing, replacement) -> existing));
|
||||
log.info("customerId = {} - tableName = {} - proSet = {}", customerId, tableName, proMap.keySet());
|
||||
|
||||
// 合并所有 key
|
||||
|
Reference in New Issue
Block a user