通过启用了功能区的客户端调用微服务时失败(没有eureka服务发现) [英] Failure while calling a microservice via ribbon enabled client(Without eureka service discovery)

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

问题描述

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

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

java.lang.IllegalStateException:没有适用于员工微服务的实例

java.lang.IllegalStateException: No instances available for employee-microservice

我正在关注用于客户端负载平衡的官方spring.io链接( 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/客户端负载平衡/

    我们的IPing是一个PingUrl,它将对URL进行ping操作以检查每个服务器的状态.回忆一下,您好,您好,有一个映射到/路径的方法;这意味着Ribbon对运行中的Say Hello服务器执行ping操作时将获得HTTP 200响应.我们设置的IRule(可用性过滤规则)将使用Ribbon的内置断路器功能来过滤处于断路"状态的任何服务器:如果ping无法连接到给定的服务器,或者读取失败对于服务器,Ribbon将认为该服务器死机",直到它开始正常响应为止.

    Our IPing is a PingUrl, which will ping a URL to check the status of each server. Say Hello has, as you’ll recall, a method mapped to the / path; that means that Ribbon will get an HTTP 200 response when it pings a running Say Hello server. The IRule we set up, the AvailabilityFilteringRule, will use Ribbon’s built-in circuit breaker functionality to filter out any servers in an "open-circuit" state: if a ping fails to connect to a given server, or if it gets a read failure for the server, Ribbon will consider that server "dead" until it begins to respond normally.

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

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆