Package gov.usgs.earthquake.nats
Class NATSClient
java.lang.Object
gov.usgs.earthquake.nats.NATSClient
- All Implemented Interfaces:
Configurable
Manages conserved NATS Streaming connection properties. Written so several
concurrent connections can be created.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConstructor for testingNATSClient
(String serverHost, String serverPort, String clusterId, String clientIdSuffix) Custom constructor -
Method Summary
Modifier and TypeMethodDescriptionvoid
Configures the required and optional parameters to connect to NATS Streaming serverio.nats.streaming.StreamingConnection
getName()
Get this object name.void
setClientId
(String clientId) void
setClusterId
(String clusterId) void
setConnection
(io.nats.streaming.StreamingConnection connection) void
Set this object name.void
setServerHost
(String serverHost) void
setServerPort
(String serverPort) void
shutdown()
Safely closes connection to NATS Streaming servervoid
startup()
Starts connection to NATS streaming server
-
Field Details
-
LOGGER
Logger object -
SERVER_HOST_PROPERTY
Property for server host -
SERVER_PORT_PROPERTY
Property for server port -
CLUSTER_ID_PROPERTY
Property for cluster id -
CLIENT_ID_PROPERTY
Property for client id -
SUBJECT_PROPERTY
Property for subject
-
-
Constructor Details
-
NATSClient
public NATSClient()Constructor for testing -
NATSClient
Custom constructor- Parameters:
serverHost
- String of hostserverPort
- String of portclusterId
- String of clusterIDclientIdSuffix
- String of idSuffix
-
-
Method Details
-
configure
Configures the required and optional parameters to connect to NATS Streaming server- Specified by:
configure
in interfaceConfigurable
- Parameters:
config
- the Config to load.- Throws:
Exception
- if error occurs
-
startup
Starts connection to NATS streaming server- Specified by:
startup
in interfaceConfigurable
- 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 interfaceConfigurable
-
getName
Description copied from interface:Configurable
Get this object name.- Specified by:
getName
in interfaceConfigurable
- Returns:
- the name.
-
setName
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 interfaceConfigurable
- Parameters:
string
- the name.
-
getServerHost
- Returns:
- serverHost
-
setServerHost
- Parameters:
serverHost
- to set
-
getServerPort
- Returns:
- serverPort
-
setServerPort
- Parameters:
serverPort
- to set
-
getClusterId
- Returns:
- clusterID
-
setClusterId
- Parameters:
clusterId
- to set
-
getClientId
- Returns:
- clientID
-
setClientId
- 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
-