我在 localhost:8500 上有领事代理服务器。然后我有一个简单的http服务器,首先在consul中注册
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");
}
但是 consuls 的健康检查器仍然说 Check 现在对我的服务至关重要