Skip to content
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

书第43页右下角,案例编写有误 #8

Open
wangpengxiang1996 opened this issue Sep 26, 2022 · 1 comment
Open

书第43页右下角,案例编写有误 #8

wangpengxiang1996 opened this issue Sep 26, 2022 · 1 comment

Comments

@wangpengxiang1996
Copy link

ed680fc3833acd3612bcc5913b983ae6

43页右下角的"hello"接口。这个案例讲的是使用ReactiveDsicoveryClient获取服务实例并切用WebClient这种reactive客户端调用服务,所以这里获取服务实例不应该通过DiscoveryClient而是通过ReactiveDsicoveryClient。并且这个类也不应该出现DiscoveryClient

deep-in-spring-cloud-samples/chapter02/spring-cloud-alibaba-nacos-consumer-reactive/src/main/java/deep/in/spring/cloud/NacosReactiveConsumer.java /

@wangpengxiang1996
Copy link
Author

@GetMapping("/hello")
public Mono hello() {
Flux instances = reactiveDiscoveryClient.getInstances(serviceName);
// 从服务实例中取第一个
ServiceInstance serviceInstance = instances.blockFirst();
// 使用WebClient调用服务实例对应的节点信息中的“/echo”方法
return WebClient.create("http://" + serviceInstance.getHost() + ":" + serviceInstance.getPort())
.get()
.uri("/echo?name=nacos")
.retrieve()
.bodyToMono(String.class);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant