Package com.networknt.consul.client
Class ConsulClientImpl
- java.lang.Object
-
- com.networknt.consul.client.ConsulClientImpl
-
- All Implemented Interfaces:
ConsulClient
public class ConsulClientImpl extends Object implements ConsulClient
A client that talks to Consul agent with REST API. Client and connection are cached as instance variable in singleton class.- Author:
- Steve Hu
-
-
Constructor Summary
Constructors Constructor Description ConsulClientImpl()
Construct ConsulClient with all parameters from consul.yml config file.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
checkFail(String serviceId, String token)
Set specific serviceId status as failvoid
checkPass(String serviceId, String token)
Set specific serviceId status as passConsulResponse<List<ConsulService>>
lookupHealthService(String serviceName, String tag, long lastConsulIndex, String token)
to lookup health services based on serviceName, if lastConsulIndex == 0, will get result right away.void
registerService(ConsulService service, String token)
register a consul servicevoid
unregisterService(String serviceId, String token)
unregister a consul service
-
-
-
Method Detail
-
checkPass
public void checkPass(String serviceId, String token)
Description copied from interface:ConsulClient
Set specific serviceId status as pass- Specified by:
checkPass
in interfaceConsulClient
- Parameters:
serviceId
- service idtoken
- ACL token for consul
-
checkFail
public void checkFail(String serviceId, String token)
Description copied from interface:ConsulClient
Set specific serviceId status as fail- Specified by:
checkFail
in interfaceConsulClient
- Parameters:
serviceId
- service idtoken
- ACL token for consul
-
registerService
public void registerService(ConsulService service, String token)
Description copied from interface:ConsulClient
register a consul service- Specified by:
registerService
in interfaceConsulClient
- Parameters:
service
- service objecttoken
- ACL token for consul
-
unregisterService
public void unregisterService(String serviceId, String token)
Description copied from interface:ConsulClient
unregister a consul service- Specified by:
unregisterService
in interfaceConsulClient
- Parameters:
serviceId
- service idtoken
- ACL token for consul
-
lookupHealthService
public ConsulResponse<List<ConsulService>> lookupHealthService(String serviceName, String tag, long lastConsulIndex, String token)
to lookup health services based on serviceName, if lastConsulIndex == 0, will get result right away. if lastConsulIndex != 0, will establish a long query with consul withwait
seconds.- Specified by:
lookupHealthService
in interfaceConsulClient
- Parameters:
serviceName
- service nametag
- tag that is used for filteringlastConsulIndex
- last consul indextoken
- consul token for security- Returns:
- null if serviceName is blank
-
-