继上一遍Ocelot+Consul之负载均衡
本次添加服务的健康检查配置
步骤
- 服务增加一个接口,用于健康检查
- consul配置健康检查api
1. 服务增加一个接口,用于健康检查
1.1 给sys1,sys2,sys3,增加healthCheck.json,放在/api/test/下,内容同do.json
2. consul配置健康检查api
2.1 增加check字段,check.url即上一步骤加的healthCheck.json接口,配置如下图
{
"services": [
{
"id": "sys1",
"name": "sys",
"address": "localhost",
"port": 10040,
"check": {
"id": "sys1_check",
"name": "sys1 check",
"http": "http://localhost:10040/api/test/healthCheck.json",
"tls_server_name": "",
"tls_skip_verify": false,
"method": "GET",
"header": { "Content-Type": ["application/json"] },
"body": "",
"interval": "10s",
"timeout": "1s"
}
},{
"id": "sys2",
"name": "sys",
"address": "localhost",
"port": 10041,
"check": {
"id": "sys2_check",
"name": "sys2 check",
"http": "http://localhost:10041/api/test/healthCheck.json",
"tls_server_name": "",
"tls_skip_verify": false,
"method": "GET",
"header": { "Content-Type": ["application/json"] },
"body": "",
"interval": "10s",
"timeout": "1s"
}
},{
"id": "sys3",
"name": "sys",
"address": "localhost",
"port": 10042,
"check": {
"id": "sys3_check",
"name": "sys3 check",
"http": "http://localhost:10042/api/test/healthCheck.json",
"tls_server_name": "",
"tls_skip_verify": false,
"method": "GET",
"header": { "Content-Type": ["application/json"] },
"body": "",
"interval": "10s",
"timeout": "1s"
}
}]
}