Class NATSClient

  • All Implemented Interfaces:
    Configurable

    public class NATSClient
    extends java.lang.Object
    implements Configurable
    Manages conserved NATS Streaming connection properties. Written so several concurrent connections can be created.
    • Constructor Summary

      Constructors 
      Constructor Description
      NATSClient()
      Constructor for testing
      NATSClient​(java.lang.String serverHost, java.lang.String serverPort, java.lang.String clusterId, java.lang.String clientIdSuffix)
      Custom constructor
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void configure​(Config config)
      Configures the required and optional parameters to connect to NATS Streaming server
      java.lang.String getClientId()  
      java.lang.String getClusterId()  
      io.nats.streaming.StreamingConnection getConnection()  
      java.lang.String getName()
      Get this object name.
      java.lang.String getServerHost()  
      java.lang.String getServerPort()  
      void setClientId​(java.lang.String clientId)  
      void setClusterId​(java.lang.String clusterId)  
      void setConnection​(io.nats.streaming.StreamingConnection connection)  
      void setName​(java.lang.String string)
      Set this object name.
      void setServerHost​(java.lang.String serverHost)  
      void setServerPort​(java.lang.String serverPort)  
      void shutdown()
      Safely closes connection to NATS Streaming server
      void startup()
      Starts connection to NATS streaming server
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • LOGGER

        public static java.util.logging.Logger LOGGER
        Logger object
      • SERVER_HOST_PROPERTY

        public static java.lang.String SERVER_HOST_PROPERTY
        Property for server host
      • SERVER_PORT_PROPERTY

        public static java.lang.String SERVER_PORT_PROPERTY
        Property for server port
      • CLUSTER_ID_PROPERTY

        public static java.lang.String CLUSTER_ID_PROPERTY
        Property for cluster id
      • CLIENT_ID_PROPERTY

        public static java.lang.String CLIENT_ID_PROPERTY
        Property for client id
      • SUBJECT_PROPERTY

        public static java.lang.String SUBJECT_PROPERTY
        Property for subject
    • Constructor Detail

      • NATSClient

        public NATSClient()
        Constructor for testing
      • NATSClient

        public NATSClient​(java.lang.String serverHost,
                          java.lang.String serverPort,
                          java.lang.String clusterId,
                          java.lang.String clientIdSuffix)
        Custom constructor
        Parameters:
        serverHost - String of host
        serverPort - String of port
        clusterId - String of clusterID
        clientIdSuffix - String of idSuffix
    • Method Detail

      • configure

        public void configure​(Config config)
                       throws java.lang.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:
        java.lang.Exception - if error occurs
      • startup

        public void startup()
                     throws java.lang.Exception
        Starts connection to NATS streaming server
        Specified by:
        startup in interface Configurable
        Throws:
        java.lang.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 java.lang.String getName()
        Description copied from interface: Configurable
        Get this object name.
        Specified by:
        getName in interface Configurable
        Returns:
        the name.
      • setName

        public void setName​(java.lang.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 java.lang.String getServerHost()
        Returns:
        serverHost
      • setServerHost

        public void setServerHost​(java.lang.String serverHost)
        Parameters:
        serverHost - to set
      • getServerPort

        public java.lang.String getServerPort()
        Returns:
        serverPort
      • setServerPort

        public void setServerPort​(java.lang.String serverPort)
        Parameters:
        serverPort - to set
      • getClusterId

        public java.lang.String getClusterId()
        Returns:
        clusterID
      • setClusterId

        public void setClusterId​(java.lang.String clusterId)
        Parameters:
        clusterId - to set
      • getClientId

        public java.lang.String getClientId()
        Returns:
        clientID
      • setClientId

        public void setClientId​(java.lang.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