-
Notifications
You must be signed in to change notification settings - Fork 8.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Failed to resolve 'xxx' [A(1)] after 6 queries" occur with WebClient but RestTemplate call success with Nacos Discovery 2022.0.0.0 #3918
Comments
from the debug information, I found the project use netty DNS resolver to resolve the service name. Then I add the DeferringLoadBalancerExchangeFilterFunction in the webclient, it is successful to find the service with service name. ==================== the 2nd call ======================================== |
nacos 2.4.3 sca 目前应该没有更新到,可以用最新的版本试试看 |
it is resolved. |
When I call interface with WebClient and RestTemplate, and the type of RestTemplate is successful but the other occur RuntimeException: Failed to fetch user: Failed to resolve 'zy-cloud-user' [A(1)] after 6 queries.
Which Component
[Nacos Discovery] com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-discovery -> 2022.0.0.0
Describe what problem you have encountered
There is a Spring WebFlux project with 4 modules: zy-cloud-common, zy-cloud-gateway, zy-cloud-auth, zy-cloud-user.
I use nacos-discovery and nacos-config to manage configuration and service. and the nacos server is 2.4.3, the project integrated with
com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-discovery -> 2022.0.0.0 and com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-config -> 2022.0.0.0;
When I call one endpoint in zy-cloud-user with WebClient, it failed and throws exception as following:
java.lang.RuntimeException: Failed to fetch user: Failed to resolve 'zy-cloud-user' [A(1)] after 6 queries
at com.zy.cloud.auth.rpc.WebClientRemoteCall.lambda$findByUsername$0(WebClientRemoteCall.java:36) ~[classes!/:na]
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
Error has been observed at the following site(s):
*__checkpoint ⇢ Handler com.zy.cloud.auth.controller.AuthController#login(Map) [DispatcherHandler]
Original Stack Trace:
at com.zy.cloud.auth.rpc.WebClientRemoteCall.lambda$findByUsername$0(WebClientRemoteCall.java:36) ~[classes!/:na]
at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onError(FluxOnErrorResume.java:94) ~[reactor-core-3.5.5.jar!/:3.5.5]
at reactor.core.publisher.MonoFlatMap$FlatMapMain.onError(MonoFlatMap.java:180) ~[reactor-core-3.5.5.jar!/:3.5.5]
at reactor.core.publisher.FluxContextWrite$ContextWriteSubscriber.onError(FluxContextWrite.java:121) ~[reactor-core-3.5.5.jar!/:3.5.5]
at reactor.core.publisher.FluxDoFinally$DoFinallySubscriber.onError(FluxDoFinally.java:119) ~[reactor-core-3.5.5.jar!/:3.5.5]
at reactor.core.publisher.MonoPeekTerminal$MonoTerminalPeekSubscriber.onError(MonoPeekTerminal.java:258) ~[reactor-core-3.5.5.jar!/:3.5.5]
at reactor.core.publisher.FluxPeekFuseable$PeekConditionalSubscriber.onError(FluxPeekFuseable.java:903) ~[reactor-core-3.5.5.jar!/:3.5.5]
at reactor.core.publisher.Operators$MultiSubscriptionSubscriber.onError(Operators.java:2210) ~[reactor-core-3.5.5.jar!/:3.5.5]
at reactor.core.publisher.FluxPeek$PeekSubscriber.onError(FluxPeek.java:222) ~[reactor-core-3.5.5.jar!/:3.5.5]
at reactor.core.publisher.FluxMap$MapSubscriber.onError(FluxMap.java:134) ~[reactor-core-3.5.5.jar!/:3.5.5]
src/main/resources/META-INF/spring.factories
org.springframework.boot.autoconfigure.EnableAutoConfiguration=
com.zy.cloud.common.WebClientConfig
----------------------WebClientConfig.java --------------------------
package com.zy.cloud.common;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
@slf4j
@configuration
public class WebClientConfig {
}
----------------------WebClientRemoteCall.java -------------------------
package com.zy.cloud.auth.rpc;
import com.zy.cloud.common.model.UserDTO;
import reactor.core.publisher.Mono;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.beans.factory.annotation.Autowired;
@service
public class WebClientRemoteCall implements BaseRemoteCall {
}
---------------------------zy-cloud-auth launch log-----------------------------
2024-12-05T13:20:32.532+08:00 DEBUG 15548 --- [ main] c.a.c.n.c.NacosConfigDataLoader : [Nacos Config] config[dataId=zy-cloud-auth.yml, group=ZY-AIANALYSIS] content:
server:
port: 9200
servlet:
context-path: /
spring:
cloud:
loadbalancer:
ribbon:
enabled: false
Describe what information you have read
zy-cloud-user and zy-cloud-auth are running in the same machine with different ports.
when the trouble occur, I change the service name into IP:port, it is successful.
return webClientBuilder
// .baseUrl("http://zy-cloud-user")
.baseUrl("http://192.168.3.109:9100")
.build()
.get()
.uri("/users/username/{username}", username)
.retrieve()
.bodyToMono(UserDTO.class)
.onErrorResume(e -> Mono.error(new RuntimeException("Failed to fetch user: " + e.getMessage())));
Then I use RestTemplate instead of WebClient, it is successful.
public Mono findByUsername(String username) {
return Mono.fromCallable(() ->
restTemplate.getForObject("http://zy-cloud-user/users/username/" + username, UserDTO.class)
).subscribeOn(Schedulers.boundedElastic());
}
The text was updated successfully, but these errors were encountered: