我正在尝试建立一个简单的Spring云领事应用程序。
我有一个"发行版"服务并在领事中注册(spring.application.name属性设置为"分发")
我有一个"收购"试图打电话给"发布"使用假装服务。
这是我的主要课程
@Configuration
@EnableAutoConfiguration
@EnableDiscoveryClient
@RestController
@EnableFeignClients
@EnableHystrix
public class Acquisition {
@Autowired
private DiscoveryClient discoveryClient;
@Autowired
private DistributionClient distributionClient;
@RequestMapping("/use-feign")
public String sendData() {
distributionClient.sendData(new Data("Hello World"));
return "sent";
}
@RequestMapping("/disco")
public String disco() {
List<ServiceInstance> list = discoveryClient.getInstances("distribution");
if (list != null && list.size() > 0) {
return list.get(0).getUri().toString();
}
return null;
}
public static void main(String[] args) {
SpringApplication.run(Acquisition.class, args);
}
}
这是我的假装客户
@FeignClient(value = "distribution")
interface DistributionClient {
@RequestMapping(method = RequestMethod.POST, value = "/data", consumes = "application/json")
void sendData(Data data);
}
这是我的pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-all</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-consul-dependencies</artifactId>
<version>1.0.1.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
当我要求&#34; / disco&#34;网址,&#34;分发的网址&#34;正确检索服务,这意味着整个发现事物正在按预期工作。
但是,当我要求&#34; / use-feign&#34; url,我得到以下异常:
com.netflix.client.ClientException:负载均衡器没有 客户端的可用服务器:分发在 com.netflix.loadbalancer.LoadBalancerContext.getServerFromLoadBalancer(LoadBalancerContext.java:468) 〜[ribbon-loadbalancer-2.2.0.jar:2.2.0] at com.netflix.loadbalancer.reactive.LoadBalancerCommand $ 1.call(LoadBalancerCommand.java:184) 〜[ribbon-loadbalancer-2.2.0.jar:2.2.0] at com.netflix.loadbalancer.reactive.LoadBalancerCommand $ 1.call(LoadBalancerCommand.java:180) 〜[ribbon-loadbalancer-2.2.0.jar:2.2.0] at rx.Observable.unsafeSubscribe(Observable.java:8460) 〜[rxjava-1.1.5.jar:1.1.5] at rx.internal.operators.OnSubscribeConcatMap.call(OnSubscribeConcatMap.java:94) 〜[rxjava-1.1.5.jar:1.1.5] at rx.internal.operators.OnSubscribeConcatMap.call(OnSubscribeConcatMap.java:42) 〜[rxjava-1.1.5.jar:1.1.5]
我错过了任何配置吗?
感谢您的帮助。
答案 0 :(得分:0)
spencergibb指出了问题:未部署健康检查端点。 只需将spring-boot-actuator添加到依赖项就可以解决问题。
答案 1 :(得分:0)
就我而言,我有:spring-boot (2.4.2)
和 spring-cloud 2020.0.1
,我刚刚添加了:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>