本文介绍了通过启用了功能区的客户端调用微服务时失败(没有eureka服务发现)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过启用了功能区的客户端(功能区客户端)调用微服务"(微服务生产者),但这给我一个错误.

I am trying to call a 'microservice'(microservice-producer) via ribbon enabled the client(ribbon-client) but it is giving me an error.

我正在关注用于客户端负载平衡的官方spring.io链接( https://spring.io/guides/gs/client-side-load-balancing/),我也遵循此链接中给出的所有规范.您可以在我的GitHub地址上查看代码: ( https://github.com/vickygupta0017/microservice-ribbon ).

I am following the official spring.io link for the client side load balancing(https://spring.io/guides/gs/client-side-load-balancing/) and I am also following all the specification given at this link.You can see the code at my GitHub address : (https://github.com/vickygupta0017/microservice-ribbon).

我不确定我错过了什么或做错了什么,有人可以帮我吗?

I am not sure what I am missing or doing wrong, could someone please help me out?

推荐答案

如果未使用eureka服务器标识服务器是否可访问,功能区客户端将使用"RibbonConfiguration"-pingUrl参数.默认情况下,它是空字符串,这意味着它将在没有任何上下文的情况下对服务器列表执行ping操作,以获取服务器是否可访问的答案.所以在这里您可以做两件事.

In case where eureka server is not used to identify whether server is reachable or not , ribbon client uses "RibbonConfiguration" - pingUrl parameter.By Default it is empty string that means it is going to ping list of server without any context to get an answer whether server is reachable or not.So here you can do 2 things.

  1. 创建绑定到服务器"/"的根上下文的服务,并发送肯定的响应.

  1. Create a service that is bound to root context of the server "/" and send a positive response.

@RequestMapping(value = "/")
public String status(HttpServletRequest request) {
    return "";
}

  • 或更新功能区客户端配置(EmployeeConfiguration)并返回带有相关服务名称"的PingUrl.

  • Or update Ribbon client Configuration (EmployeeConfiguration) and return PingUrl with relevant "service-name".

    @Bean
    public IPing ribbonPing(IClientConfig config) {
       return new PingUrl(false,"/employees");
    }
    

  • 选择第一个,因为它将解决基本目的,以查看服务器是否可访问.

    Go for the first one as it will solve the basic purpose to see if server is reachable or not.

    参考: https://spring.io/guides/gs/客户端负载平衡/

    这篇关于通过启用了功能区的客户端调用微服务时失败(没有eureka服务发现)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    06-26 12:26