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 voidcheckFail(String serviceId, String token)Set specific serviceId status as failvoidcheckPass(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.voidregisterService(ConsulService service, String token)register a consul servicevoidunregisterService(String serviceId, String token)unregister a consul service
-
-
-
Method Detail
-
checkPass
public void checkPass(String serviceId, String token)
Description copied from interface:ConsulClientSet specific serviceId status as pass- Specified by:
checkPassin interfaceConsulClient- Parameters:
serviceId- service idtoken- ACL token for consul
-
checkFail
public void checkFail(String serviceId, String token)
Description copied from interface:ConsulClientSet specific serviceId status as fail- Specified by:
checkFailin interfaceConsulClient- Parameters:
serviceId- service idtoken- ACL token for consul
-
registerService
public void registerService(ConsulService service, String token)
Description copied from interface:ConsulClientregister a consul service- Specified by:
registerServicein interfaceConsulClient- Parameters:
service- service objecttoken- ACL token for consul
-
unregisterService
public void unregisterService(String serviceId, String token)
Description copied from interface:ConsulClientunregister a consul service- Specified by:
unregisterServicein 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 withwaitseconds.- Specified by:
lookupHealthServicein interfaceConsulClient- Parameters:
serviceName- service name (service_id)tag- tag that is used for filtering (env_tag)lastConsulIndex- last consul indextoken- Consul token for security (Consul ACL)- Returns:
- if Consul connection fails: - newResponse is null if Consul connection successful: - newResponse is non-null, and - newResponse.getValue() != null, and - newResponse.getValue().size() == number of IPs registered for serviceName in Consul
-
-