Class 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 Detail

      • ConsulClientImpl

        public ConsulClientImpl()
        Construct ConsulClient with all parameters from consul.yml config file. The other two constructors are just for backward compatibility.
    • 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 interface ConsulClient
        Parameters:
        serviceId - service id
        token - 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 interface ConsulClient
        Parameters:
        serviceId - service id
        token - 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 interface ConsulClient
        Parameters:
        serviceId - service id
        token - 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 with wait seconds.
        Specified by:
        lookupHealthService in interface ConsulClient
        Parameters:
        serviceName - service name
        tag - tag that is used for filtering
        lastConsulIndex - last consul index
        token - consul token for security
        Returns:
        null if serviceName is blank