当前位置: 首页 > 知识库问答 >
问题:

Spring引导应用程序的 Consul 服务发现问题

司寇飞航
2023-03-14

根据这篇基于尤里卡服务发现的博客https://spring.io/blog/2015/07/14/microservices-with-spring,服务发现在这里正常工作。

但是当切换到使用Consul而不是Eureka时,服务发现不起作用,并出现以下错误:

java.lang.IllegalStateException: No instances available for ACCOUNTS-SERVICE
at org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.execute(RibbonLoadBalancerClient.java:79)
at org.springframework.cloud.client.loadbalancer.LoadBalancerInterceptor.intercept(LoadBalancerInterceptor.java:46) ...

更新:在通过提供正确的运行状况检查endpoint(请参阅下面的答案)修复上一个错误后,在bootstrap.yml中正确提供Consul服务器的主机和端口将服务部署到Cloud Foundry(在“bootstrap”阶段加载的基于Consul的PropertySource):

---
spring:
  profiles: cloud
  cloud:
    consul:
      host: <consul host or ip>
      port: 8500

Consul正在注册服务,但状态严重(失败)!

将感谢任何帮助或指导。

谢谢

共有1个答案

江浩慨
2023-03-14

该问题与Consul健康检查默认路径有关,该路径设置为 /healthendpoint。因此,在所有客户端应用程序(Web服务器和微服务)中启用Spring执行器后,此问题得到了解决。

或者,您可以更改bootstrap.yml文件中的默认领事健康检查终结点:

  cloud:
    consul:
      discovery:
        healthCheckPath: /test

铌。为了在 maven 中启用Spring执行器,将以下依赖项添加到 pom.xml 文件中:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

欲了解更多信息,请访问http://cloud . spring . io/spring-cloud-consult/spring-cloud-consult . html

在部署(推送)到CF (CloudFoundry)时,部署的应用程序的URI应该提供给Consul用于服务发现过程(CF在vcap.application.uris环境变量中提供应用程序的URIs),因此应该将以下配置添加到bootsrap.yml文件中:

---
spring:
  profiles: cloud
  cloud:
    consul:
      host: <consul host or ip>
      port: 8500
      discovery:
        instanceId: ${spring.application.name}:${vcap.application.application_name}:${vcap.application.instance_id}
        hostname: ${vcap.application.uris[0]}
        port: 80

NB。Consul使用instanceId来注册应用程序(微服务)实例

 类似资料:
  • 服务发现是基于微服务架构的关键原则之一。尝试配置每个客户端或某种形式的约定可能非常困难,可以非常脆弱。Consul通过HTTP API和DNS提供服务发现服务。Spring Cloud Consul利用HTTP API进行服务注册和发现。这不会阻止非Spring Cloud应用程序利用DNS界面。Consul代理服务器在通过八卦协议进行通信的集群中运行,并使用Raft协议协议。 如何激活 要激活C

  • Consul 是 HashiCorp 公司推出的开源工具,用于实现分布式系统的服务发现与配置。与其他分布式服务注册与发现的方案,Consul的方案更“一站式”,内置了服务注册与发现框 架、分布一致性协议实现、健康检查、Key/Value存储、多数据中心方案,不再需要依赖其他工具(比如ZooKeeper等)。使用起来也较 为简单。Consul使用Go语言编写,因此具有天然可移植性(支持Linux、w

  • 我是Spring应用程序开发的新手。 如何在tomcat服务器的开发阶段运行我的应用程序。 在这里我可以看到最终部署的解决方案。每次我需要停下来重新开始时,我只需要在ui上更改一些。这让我很难受。所以你能帮我照顾她吗?? 我的pom.xml依赖是 org.springframework spring-binding 1.0.6

  • 1、前言 本文通过创建 provider-service、consumer-service 两个微服务,并通过 feign 接口调用来演示 Spring Cloud 整合 Consul。阅读本文需要前置知识: Spring Boot Spring Cloud Spring Cloud Feign 2、搭建 provider-service 服务 2.1、创建 maven 模块 创建provider

  • 我遇到的问题,而试图使用Spring开机与是(WebSphere)服务器。我有一个网页,接受输入,然后执行@控制器类。 任何帮助都将不胜感激。这是什么特别的,我们需要做在POM. xmlIBMWebSphere。 下面是我的应用课程内容。 我已经加了 Spring boot:run提供了以下错误跟踪。

  • 我有一个遗留代码,其中一个Spring Boot应用程序在服务启动后向consul注册。该应用程序自动装配ConsulLifesycle Spring bean,通过它使用其内建方法ConsulLifecycle.start()和ConsulLifecycle.stop()向consul注册/取消注册服务。 现在我们把spring升级到了5.1.5,spring-cloud-starter-con