我正在尝试设置一个简单的春季云领事应用程序。
我有一个"分发"服务并在领事中注册(带有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>
当我请求"/迪斯科" URL时,"分发"服务的URL得到了正确检索,这意味着整个发现事物正在按预期工作。
但是,当我请求"/use-feign" URL时,我会得到以下例外:
com.netflix.client.ClientException:Load Balancer没有 可用于客户端的服务器:在 com.netflix.loadbalancer.loadbalancercontext.getserverfromloadbalancer(loadBalancercOrtext.java:468) 〜[Ribbon-LoadBalancer-2.2.0.jar:2.2.0] com.netflix.loadbalancer.reactive.loadbalancercommand $ 1.CALL(loadBalancerCommand.java:184) 〜[Ribbon-LoadBalancer-2.2.0.jar:2.2.0] com.netflix.loadbalancer.reactive.loadbalancercommand $ 1.CALL(loadBalancerCommand.java:180) 〜[Ribbon-LoadBalancer-2.2.0.jar:2.2.0] rx.Observable.unsafeSubscribe(observable.java:8460) 〜[rxjava-1.1.5.5.jar:1.1.5] at rx.internal.operators.onsubscribeconcatmap.call(onsubscribeconcatmap.java:94) 〜[rxjava-1.1.5.5.jar:1.1.5] at rx.internal.operators.onsubscribeconcatmap.call(onsubscribeconcatmap.java:42) 〜[rxjava-1.1.5.5.jar:1.1.5]
我是否缺少任何配置?
谢谢您的帮助。
spencergibb指出了问题:没有部署健康检查端点。只是将弹簧启动器添加到依赖项解决问题。
在我的情况下,我有: spring-boot (2.4.2)
带有 spring-cloud 2020.0.1
,我刚刚添加了:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>