Class NATSClient

java.lang.Object
gov.usgs.earthquake.nats.NATSClient
All Implemented Interfaces:
Configurable

public class NATSClient extends Object implements Configurable
Manages conserved NATS Streaming connection properties. Written so several concurrent connections can be created.
  • Field Details

    • LOGGER

      public static Logger LOGGER
      Logger object
    • SERVER_HOST_PROPERTY

      public static String SERVER_HOST_PROPERTY
      Property for server host
    • SERVER_PORT_PROPERTY

      public static String SERVER_PORT_PROPERTY
      Property for server port
    • CLUSTER_ID_PROPERTY

      public static String CLUSTER_ID_PROPERTY
      Property for cluster id
    • CLIENT_ID_PROPERTY

      public static String CLIENT_ID_PROPERTY
      Property for client id
    • SUBJECT_PROPERTY

      public static String SUBJECT_PROPERTY
      Property for subject
  • Constructor Details

    • NATSClient

      public NATSClient()
      Constructor for testing
    • NATSClient

      public NATSClient(String serverHost, String serverPort, String clusterId, String clientIdSuffix)
      Custom constructor
      Parameters:
      serverHost - String of host
      serverPort - String of port
      clusterId - String of clusterID
      clientIdSuffix - String of idSuffix
  • Method Details

    • configure

      public void configure(Config config) throws Exception
      Configures the required and optional parameters to connect to NATS Streaming server
      Specified by:
      configure in interface Configurable
      Parameters:
      config - the Config to load.
      Throws:
      Exception - if error occurs
    • startup

      public void startup() throws Exception
      Starts connection to NATS streaming server
      Specified by:
      startup in interface Configurable
      Throws:
      Exception - If something goes wrong when connecting to NATS streaming server
    • shutdown

      public void shutdown()
      Safely closes connection to NATS Streaming server
      Specified by:
      shutdown in interface Configurable
    • getName

      public String getName()
      Description copied from interface: Configurable
      Get this object name.
      Specified by:
      getName in interface Configurable
      Returns:
      the name.
    • setName

      public void setName(String string)
      Description copied from interface: Configurable
      Set this object name. This method is typically called by a Config object when the configurable object is loaded out of a config file. name will be set to the config section.
      Specified by:
      setName in interface Configurable
      Parameters:
      string - the name.
    • getServerHost

      public String getServerHost()
      Returns:
      serverHost
    • setServerHost

      public void setServerHost(String serverHost)
      Parameters:
      serverHost - to set
    • getServerPort

      public String getServerPort()
      Returns:
      serverPort
    • setServerPort

      public void setServerPort(String serverPort)
      Parameters:
      serverPort - to set
    • getClusterId

      public String getClusterId()
      Returns:
      clusterID
    • setClusterId

      public void setClusterId(String clusterId)
      Parameters:
      clusterId - to set
    • getClientId

      public String getClientId()
      Returns:
      clientID
    • setClientId

      public void setClientId(String clientId)
      Parameters:
      clientId - to set
    • getConnection

      public io.nats.streaming.StreamingConnection getConnection()
      Returns:
      StreamingConnection
    • setConnection

      public void setConnection(io.nats.streaming.StreamingConnection connection)
      Parameters:
      connection - StreamingConnection to set