Проверка работоспособности Spring Cloud Consul и настройка статуса на GCP

Мы пытаемся зарегистрировать spring-cloud-consul приложение с consul в вычислительный движок GCP, где он может зарегистрировать приложение в консуле, но с приложением мы сталкиваемся с двумя проблемами. Ниже приведены bootstrap.yaml и server.yaml для приложения,

application.yaml

server:
  port: 10003
spring:
  application:
    name: hello-service
  cloud:
    consul:
      enabled: true
    inetutils:
      useOnlySiteLocalInterfaces: true
  endpoints:
    actuator:
      sensitive: false

bootstrap.yaml

spring:
  cloud:
    consul:
      enabled: true
      host: 10.160.0.18
      port: 8500
      discovery:
        prefer-ip-address: true
  1. Consul не может вызвать проверку работоспособности на вычислительном движке, возможно, потому, что он зарегистрирован на внутреннем доменном имени экземпляра.

сервис с консулом: NewService{id='hello-service-10003', name='hello-service', tags=[secure=false], address='consul-app-test.c.name-of-project.internal ', meta=null, port=10003, enableTagOverride=null, check=Check{script='null', interval='10s', ttl='null', http='http://consul-app-test.c.name-of-project.internal:10003/actuator/health', method='null', header={}, tcp='null', timeout='null', deregisterCriticalServiceAfter='null', tlsSkipVerify=null, status='null'}, checks= нулевой}

  1. Заявление о снятии с учета с консула. Мы остановили приложение, но оно все еще отображается в пользовательском интерфейсе консула.

person Nitishkumar Singh    schedule 21.02.2019    source источник


Ответы (2)


Я внес несколько изменений в файлы application.yaml и bootstrap.yaml, которые мне подошли.

application.yaml

spring:
  application:
    name: hello-service
  cloud:
    consul:
      discovery:
        instanceId: ${spring.application.name}:${random.value}
        health-check-critical-timeout: 3m
        prefer-ip-address: true # disable if we want to use google cloud internal DNS 

bootstrap.yaml

spring:
  cloud:
    consul:
      enabled: true
      host: 10.160.0.18
      port: 8500
person Nitishkumar Singh    schedule 02.03.2019

если вы используете версию 2.1.2, как я: org.springframework.cloud:spring-cloud-starter-consul-discovery:2.1.2.RELEASE

вы можете установить:

spring:

  cloud:
    consul:
      host: localhost #  consul的地址
      port: 8500 # consul 的端口
      discovery:
        prefer-ip-address: true  # // This must be matched
        tags: version=1.0
        instance-id: ${spring.application.name}:${spring.cloud.client.ip-address}
        healthCheckPath: /actuator/health # 服务做健康检查的端口
        healthCheckInterval: 15s  # 服务健康检查的周期
        healthCheckTimeout: 60s # 服务检查是的timeout时长
        healthCheckCriticalTimeout: 5m # 服务健康检查失败5分钟后,删除服务

и вы можете посмотреть исходный код в ConsulDiscoveryProperties:

@ConfigurationProperties("spring.cloud.consul.discovery")
public class ConsulDiscoveryProperties {

……

    /** Is service discovery enabled? */
    private boolean enabled = true;

    /** Alternate server path to invoke for health checking. */
    private String healthCheckPath = "/actuator/health";

    /** Custom health check url to override default. */
    private String healthCheckUrl;

    /** How often to perform the health check (e.g. 10s), defaults to 10s. */
    private String healthCheckInterval = "10s";

    /** Timeout for health check (e.g. 10s). */
    private String healthCheckTimeout;

    /**
     * Timeout to deregister services critical for longer than timeout (e.g. 30m).
     * Requires consul version 7.x or higher.
     */
    private String healthCheckCriticalTimeout;
……
person Bruce    schedule 17.10.2019