领事健康检查员

时间:2020-06-03 13:04:50

标签: java consul consul-health-check

我在localhost:8500上有领事代理服务器。 然后我有一个简单的http服务器,该服务器首先在领事中注册

    Consul client = Consul.builder().build(); // connect on localhost
    AgentClient agentClient = client.agentClient();

    String serviceId = "1";
    Registration.RegCheck regCheck = ImmutableRegCheck.builder()
            .http("localhost:8080/api/rocks/healthCheck")
            .interval("5s")
            .timeout("1s")
            .build();
    Registration service = ImmutableRegistration.builder()
            .id(serviceId)
            .name("myService")
            .port(8080)
            .check(regCheck) // registers with a TTL of 3 seconds
            .tags(Collections.singletonList("tag1"))
            .meta(Collections.singletonMap("version", "1.0"))
            .build();

    agentClient.register(service);

如果收到“ healthCheck”请求,我就会回答

@GetMapping(value = "/healthCheck")
public ResponseEntity<String> healthCheck() {
    log.info("RocksApi.healthCheck");
    return ResponseEntity.ok("ok");
}

但是领事的健康检查人员仍然说,检查对我的服务现在至关重要

1 个答案:

答案 0 :(得分:0)

好像您的健康检查网址可能有误。在您的客户端构建器中,您说“ api / rocks / healthCheck”,但只能通过路径“ / healthCheck”访问端点。