Package io.nats.client
Class Options
- java.lang.Object
-
- io.nats.client.Options
-
public class Options extends java.lang.ObjectThe Options class specifies the connection options for a new NATs connection, including the default options. Options are created using aBuilder. This class, and the builder associated with it, is basically a long list of parameters. The documentation attempts to clarify the value of each parameter in place on the builder and here, but it may be easier to read the documentation starting with theBuilder, since it has a simple list of methods that configure the connection.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classOptions.BuilderOptions are created using a Builder.
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_BUFFER_SIZEDefault size for buffers in the connection, not as available as other settings, this is primarily changed for testing,getBufferSize().static java.time.DurationDEFAULT_CONNECTION_TIMEOUTDefault connection timeout, seegetConnectionTimeout().static java.lang.StringDEFAULT_DATA_PORT_TYPEDefault dataport class, which will use a TCP socket,getDataPortType().static java.lang.StringDEFAULT_INBOX_PREFIXDefault prefix used for inboxes, you can change this to manage authorization of subjects.static intDEFAULT_MAX_CONTROL_LINEThe default length, 1024 bytes, the client will allow in an outgoing protocol control line,getMaxControlLine().static intDEFAULT_MAX_PINGS_OUTDefault maximum number of pings have not received a response allowed by the client,getMaxPingsOut().static intDEFAULT_MAX_RECONNECTDefault maximum number of reconnect attempts, seegetMaxReconnect().static java.time.DurationDEFAULT_PING_INTERVALDefault server ping interval.static intDEFAULT_PORTDefault server port.static intDEFAULT_RECONNECT_BUF_SIZEDefault of pending message buffer that is used for buffering messages that are published during a disconnect/reconnect,getReconnectBufferSize().static java.time.DurationDEFAULT_RECONNECT_WAITDefault wait time before attempting reconnection to the same server, seegetReconnectWait().static java.time.DurationDEFAULT_REQUEST_CLEANUP_INTERVALDefault interval to clean up cancelled/timed out requests.static java.lang.StringDEFAULT_SSL_PROTOCOLDefault SSL protocol used to create an SSLContext if thesecure propertyis used.static java.lang.StringDEFAULT_THREAD_NAME_PREFIXDefault thread name prefix.static java.lang.StringDEFAULT_URLDefault server URL.static intMAX_MESSAGES_IN_NETWORK_BUFFERThis value is used internally to limit the number of messages sent in a single network I/O.static intMAX_MESSAGES_IN_OUTGOING_QUEUEThis value is used internally to limit the number of messages allowed in the outgoing queue.static java.lang.StringPROP_CLEANUP_INTERVALProperty used to configure a builder from a Properties object.static java.lang.StringPROP_CONNECTION_CBProperty used to configure a builder from a Properties object.static java.lang.StringPROP_CONNECTION_NAMEProperty used to configure a builder from a Properties object.static java.lang.StringPROP_CONNECTION_TIMEOUTProperty used to configure a builder from a Properties object.static java.lang.StringPROP_DATA_PORT_TYPEProperty used to configure a builder from a Properties object.static java.lang.StringPROP_ERROR_LISTENERProperty used to configure a builder from a Properties object.static java.lang.StringPROP_INBOX_PREFIXProperty used to set the inbox prefixstatic java.lang.StringPROP_MAX_CONTROL_LINEProperty used to configure a builder from a Properties object.static java.lang.StringPROP_MAX_PINGSProperty used to configure a builder from a Properties object.static java.lang.StringPROP_MAX_RECONNECTProperty used to configure a builder from a Properties object.static java.lang.StringPROP_NO_ECHOProperty used to configure a builder from a Properties object.static java.lang.StringPROP_NORANDOMIZEProperty used to configure a builder from a Properties object.static java.lang.StringPROP_OPENTLSProperty used to configure a builder from a Properties object.static java.lang.StringPROP_PASSWORDProperty used to configure a builder from a Properties object.static java.lang.StringPROP_PEDANTICProperty used to configure a builder from a Properties object.static java.lang.StringPROP_PING_INTERVALProperty used to configure a builder from a Properties object.static java.lang.StringPROP_RECONNECT_BUF_SIZEProperty used to configure a builder from a Properties object.static java.lang.StringPROP_RECONNECT_WAITProperty used to configure a builder from a Properties object.static java.lang.StringPROP_SECUREProperty used to configure a builder from a Properties object.static java.lang.StringPROP_SERVERSProperty used to configure a builder from a Properties object.static java.lang.StringPROP_TOKENProperty used to configure a builder from a Properties object.static java.lang.StringPROP_URLProperty used to configure a builder from a Properties object.static java.lang.StringPROP_USE_OLD_REQUEST_STYLEProperty used to configure a builder from a Properties object.static java.lang.StringPROP_USERNAMEProperty used to configure a builder from a Properties object.static java.lang.StringPROP_UTF8_SUBJECTSThis property is used to enable support for UTF8 subjects.static java.lang.StringPROP_VERBOSEProperty used to configure a builder from a Properties object.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description io.nats.client.impl.DataPortbuildDataPort()java.nio.CharBufferbuildProtocolConnectOptionsString(java.lang.String serverURI, boolean includeAuth, byte[] nonce)Create the options string sent with a connect message.java.net.URIcreateURIForServer(java.lang.String serverURI)AuthHandlergetAuthHandler()intgetBufferSize()ConnectionListenergetConnectionListener()java.lang.StringgetConnectionName()java.time.DurationgetConnectionTimeout()java.lang.StringgetDataPortType()ErrorListenergetErrorListener()java.util.concurrent.ExecutorServicegetExecutor()java.lang.StringgetInboxPrefix()intgetMaxControlLine()intgetMaxPingsOut()intgetMaxReconnect()java.lang.StringgetPassword()Deprecated.converts the char array to a string, use getPasswordChars instead for more securitychar[]getPasswordChars()java.time.DurationgetPingInterval()longgetReconnectBufferSize()java.time.DurationgetReconnectWait()java.time.DurationgetRequestCleanupInterval()java.util.Collection<java.net.URI>getServers()javax.net.ssl.SSLContextgetSslContext()java.lang.StringgetToken()Deprecated.converts the char array to a string, use getTokenChars instead for more securitychar[]getTokenChars()java.lang.StringgetUsername()Deprecated.converts the char array to a string, use getUserNameChars instead for more securitychar[]getUsernameChars()booleanisNoEcho()booleanisNoRandomize()booleanisOldRequestStyle()booleanisPedantic()booleanisTLSRequired()booleanisTraceConnection()booleanisTrackAdvancedStats()booleanisVerbose()booleansupportUTF8Subjects()
-
-
-
Field Detail
-
DEFAULT_URL
public static final java.lang.String DEFAULT_URL
Default server URL.This property is defined as "nats://localhost:4222"
- See Also:
- Constant Field Values
-
DEFAULT_PORT
public static final int DEFAULT_PORT
Default server port.This property is defined as 4222
- See Also:
- Constant Field Values
-
DEFAULT_MAX_RECONNECT
public static final int DEFAULT_MAX_RECONNECT
Default maximum number of reconnect attempts, seegetMaxReconnect().This property is defined as 60
- See Also:
- Constant Field Values
-
DEFAULT_RECONNECT_WAIT
public static final java.time.Duration DEFAULT_RECONNECT_WAIT
Default wait time before attempting reconnection to the same server, seegetReconnectWait().This property is defined as 2 seconds.
-
DEFAULT_CONNECTION_TIMEOUT
public static final java.time.Duration DEFAULT_CONNECTION_TIMEOUT
Default connection timeout, seegetConnectionTimeout().This property is defined as 2 seconds.}
-
DEFAULT_PING_INTERVAL
public static final java.time.Duration DEFAULT_PING_INTERVAL
Default server ping interval. The client will send a ping to the server on this interval to insure liveness. The server may send pings to the client as well, these are handled automatically by the library , seegetPingInterval().A value of
<=0means disabled.This property is defined as 2 minutes.
-
DEFAULT_REQUEST_CLEANUP_INTERVAL
public static final java.time.Duration DEFAULT_REQUEST_CLEANUP_INTERVAL
Default interval to clean up cancelled/timed out requests. A timer is used to clean up futures that were handed out but never completed via a message,getRequestCleanupInterval().This property is defined as 5 seconds.
-
DEFAULT_MAX_PINGS_OUT
public static final int DEFAULT_MAX_PINGS_OUT
Default maximum number of pings have not received a response allowed by the client,getMaxPingsOut().This property is defined as 2
- See Also:
- Constant Field Values
-
DEFAULT_SSL_PROTOCOL
public static final java.lang.String DEFAULT_SSL_PROTOCOL
Default SSL protocol used to create an SSLContext if thesecure propertyis used.This property is defined as "TLSv1.2"
- See Also:
- Constant Field Values
-
DEFAULT_RECONNECT_BUF_SIZE
public static final int DEFAULT_RECONNECT_BUF_SIZE
Default of pending message buffer that is used for buffering messages that are published during a disconnect/reconnect,getReconnectBufferSize().This property is defined as 8388608 bytes, 8 * 1024 * 1024.
- See Also:
- Constant Field Values
-
DEFAULT_MAX_CONTROL_LINE
public static final int DEFAULT_MAX_CONTROL_LINE
The default length, 1024 bytes, the client will allow in an outgoing protocol control line,getMaxControlLine().This value is configurable on the server, and should be set here to match.
- See Also:
- Constant Field Values
-
DEFAULT_DATA_PORT_TYPE
public static final java.lang.String DEFAULT_DATA_PORT_TYPE
Default dataport class, which will use a TCP socket,getDataPortType().This option is currently provided only for testing, and experimentation, the default should be used in almost all cases.
-
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZE
Default size for buffers in the connection, not as available as other settings, this is primarily changed for testing,getBufferSize().- See Also:
- Constant Field Values
-
DEFAULT_THREAD_NAME_PREFIX
public static final java.lang.String DEFAULT_THREAD_NAME_PREFIX
Default thread name prefix. Used by the default exectuor when creating threads.This property is defined as "nats"
- See Also:
- Constant Field Values
-
DEFAULT_INBOX_PREFIX
public static final java.lang.String DEFAULT_INBOX_PREFIX
Default prefix used for inboxes, you can change this to manage authorization of subjects. SeegetInboxPrefix(), the . is required but will be added if missing.- See Also:
- Constant Field Values
-
MAX_MESSAGES_IN_NETWORK_BUFFER
public static final int MAX_MESSAGES_IN_NETWORK_BUFFER
This value is used internally to limit the number of messages sent in a single network I/O. The value returned bygetBufferSize()is used first, but if the buffer size is large and the message sizes are small, this limit comes into play. The choice of 1000 is arbitrary and based on testing across several operating systems. Use buffer size for tuning.- See Also:
- Constant Field Values
-
MAX_MESSAGES_IN_OUTGOING_QUEUE
public static final int MAX_MESSAGES_IN_OUTGOING_QUEUE
This value is used internally to limit the number of messages allowed in the outgoing queue. When this limit is reached, publish requests will be blocked until the queue can clear. Because this value is in messages, the memory size associated with this value depends on the actual size of messages. If 0 byte messages are used, then MAX_MESSAGES_IN_OUTGOING_QUEUE will take up the minimal space. If 1024 byte messages are used then approximately 5Mb is used for the queue (plus overhead for subjects, etc..) We are using messages, not bytes, to allow a simplification in the underlying library, and use LinkedBlockingQueue as the core element in the queue.- See Also:
- Constant Field Values
-
PROP_CONNECTION_CB
public static final java.lang.String PROP_CONNECTION_CB
Property used to configure a builder from a Properties object. "io.nats.client.callback.connection", seeconnectionListener.- See Also:
- Constant Field Values
-
PROP_DATA_PORT_TYPE
public static final java.lang.String PROP_DATA_PORT_TYPE
Property used to configure a builder from a Properties object. "io.nats.client.dataport.type", seedataPortType.- See Also:
- Constant Field Values
-
PROP_ERROR_LISTENER
public static final java.lang.String PROP_ERROR_LISTENER
Property used to configure a builder from a Properties object. "io.nats.client.callback.error", seeerrorListener.- See Also:
- Constant Field Values
-
PROP_MAX_PINGS
public static final java.lang.String PROP_MAX_PINGS
Property used to configure a builder from a Properties object. "io.nats.client.maxpings", seemaxPingsOut.- See Also:
- Constant Field Values
-
PROP_PING_INTERVAL
public static final java.lang.String PROP_PING_INTERVAL
Property used to configure a builder from a Properties object. "io.nats.client.pinginterval", seepingInterval.- See Also:
- Constant Field Values
-
PROP_CLEANUP_INTERVAL
public static final java.lang.String PROP_CLEANUP_INTERVAL
Property used to configure a builder from a Properties object. "io.nats.client.cleanupinterval", seerequestCleanupInterval.- See Also:
- Constant Field Values
-
PROP_CONNECTION_TIMEOUT
public static final java.lang.String PROP_CONNECTION_TIMEOUT
Property used to configure a builder from a Properties object. "io.nats.client.timeout", seeconnectionTimeout.- See Also:
- Constant Field Values
-
PROP_RECONNECT_BUF_SIZE
public static final java.lang.String PROP_RECONNECT_BUF_SIZE
Property used to configure a builder from a Properties object. "io.nats.client.reconnect.buffer.size", seereconnectBufferSize.- See Also:
- Constant Field Values
-
PROP_RECONNECT_WAIT
public static final java.lang.String PROP_RECONNECT_WAIT
Property used to configure a builder from a Properties object. "io.nats.client.reconnect.wait", seereconnectWait.- See Also:
- Constant Field Values
-
PROP_MAX_RECONNECT
public static final java.lang.String PROP_MAX_RECONNECT
Property used to configure a builder from a Properties object. "io.nats.client.reconnect.max", seemaxReconnects.- See Also:
- Constant Field Values
-
PROP_PEDANTIC
public static final java.lang.String PROP_PEDANTIC
Property used to configure a builder from a Properties object. "io.nats.client.pedantic", seepedantic.- See Also:
- Constant Field Values
-
PROP_VERBOSE
public static final java.lang.String PROP_VERBOSE
Property used to configure a builder from a Properties object. "io.nats.client.verbose", seeverbose.- See Also:
- Constant Field Values
-
PROP_NO_ECHO
public static final java.lang.String PROP_NO_ECHO
Property used to configure a builder from a Properties object. "io.nats.client.noecho", seenoEcho.- See Also:
- Constant Field Values
-
PROP_CONNECTION_NAME
public static final java.lang.String PROP_CONNECTION_NAME
Property used to configure a builder from a Properties object. "io.nats.client.name", seeconnectionName.- See Also:
- Constant Field Values
-
PROP_NORANDOMIZE
public static final java.lang.String PROP_NORANDOMIZE
Property used to configure a builder from a Properties object. "io.nats.client.norandomize", seenoRandomize.- See Also:
- Constant Field Values
-
PROP_SERVERS
public static final java.lang.String PROP_SERVERS
Property used to configure a builder from a Properties object. "io.nats.client.servers", seeservers. The value can be a comma-separated list of server URLs.- See Also:
- Constant Field Values
-
PROP_PASSWORD
public static final java.lang.String PROP_PASSWORD
Property used to configure a builder from a Properties object. "io.nats.client.password", seeuserInfo.- See Also:
- Constant Field Values
-
PROP_USERNAME
public static final java.lang.String PROP_USERNAME
Property used to configure a builder from a Properties object. "io.nats.client.username", seeuserInfo.- See Also:
- Constant Field Values
-
PROP_TOKEN
public static final java.lang.String PROP_TOKEN
Property used to configure a builder from a Properties object. "io.nats.client.token", seetoken.- See Also:
- Constant Field Values
-
PROP_URL
public static final java.lang.String PROP_URL
Property used to configure a builder from a Properties object. "io.nats.client.url", seeserver.- See Also:
- Constant Field Values
-
PROP_SECURE
public static final java.lang.String PROP_SECURE
Property used to configure a builder from a Properties object. "io.nats.client.secure", seesslContext. This property is a boolean flag, but it tells the options parser to use the default SSL context. Set the default context before creating the options.- See Also:
- Constant Field Values
-
PROP_OPENTLS
public static final java.lang.String PROP_OPENTLS
Property used to configure a builder from a Properties object. "io.nats.client.opentls", seesslContext. This property is a boolean flag, but it tells the options parser to use the an SSL context that takes any server TLS certificate and does not provide its own. The server must have tls_verify turned OFF for this option to work.- See Also:
- Constant Field Values
-
PROP_USE_OLD_REQUEST_STYLE
public static final java.lang.String PROP_USE_OLD_REQUEST_STYLE
Property used to configure a builder from a Properties object. "use.old.request.style", seeoldRequestStyle.- See Also:
- Constant Field Values
-
PROP_MAX_CONTROL_LINE
public static final java.lang.String PROP_MAX_CONTROL_LINE
Property used to configure a builder from a Properties object. "max.control.line", seemaxControlLine.- See Also:
- Constant Field Values
-
PROP_UTF8_SUBJECTS
public static final java.lang.String PROP_UTF8_SUBJECTS
This property is used to enable support for UTF8 subjects. SeesupportUTF8Subjcts()- See Also:
- Constant Field Values
-
PROP_INBOX_PREFIX
public static final java.lang.String PROP_INBOX_PREFIX
Property used to set the inbox prefix- See Also:
- Constant Field Values
-
-
Method Detail
-
getExecutor
public java.util.concurrent.ExecutorService getExecutor()
- Returns:
- the executor, see
executor()in the builder doc
-
getErrorListener
public ErrorListener getErrorListener()
- Returns:
- the error listener, or null, see
errorListener()in the builder doc
-
getConnectionListener
public ConnectionListener getConnectionListener()
- Returns:
- the connection listener, or null, see
connectionListener()in the builder doc
-
getAuthHandler
public AuthHandler getAuthHandler()
- Returns:
- the auth handler, or null, see
authHandler()in the builder doc
-
getDataPortType
public java.lang.String getDataPortType()
- Returns:
- the dataport type for connections created by this options object, see
dataPortType()in the builder doc
-
buildDataPort
public io.nats.client.impl.DataPort buildDataPort()
- Returns:
- the data port described by these options
-
getServers
public java.util.Collection<java.net.URI> getServers()
- Returns:
- the servers stored in this options, see
servers()in the builder doc
-
isNoRandomize
public boolean isNoRandomize()
- Returns:
- should we turn off randomization for server connection attempts, see
noRandomize()in the builder doc
-
supportUTF8Subjects
public boolean supportUTF8Subjects()
- Returns:
- whether or not utf8 subjects are supported, see
supportUTF8Subjects()in the builder doc.
-
getConnectionName
public java.lang.String getConnectionName()
- Returns:
- the connectionName, see
connectionName()in the builder doc
-
isVerbose
public boolean isVerbose()
- Returns:
- are we in verbose mode, see
verbose()in the builder doc
-
isNoEcho
public boolean isNoEcho()
- Returns:
- is echo-ing disabled, see
noEcho()in the builder doc
-
isPedantic
public boolean isPedantic()
- Returns:
- are we using pedantic protocol, see
pedantic()in the builder doc
-
isTrackAdvancedStats
public boolean isTrackAdvancedStats()
- Returns:
- should we track advanced stats, see
turnOnAdvancedStats()in the builder doc
-
isTraceConnection
public boolean isTraceConnection()
- Returns:
- should we trace the connection process to system.out
-
getMaxControlLine
public int getMaxControlLine()
- Returns:
- the maximum length of a control line, see
maxControlLine()in the builder doc
-
isTLSRequired
public boolean isTLSRequired()
- Returns:
- true if there is an sslContext for this Options, otherwise false, see
secure()in the builder doc
-
getSslContext
public javax.net.ssl.SSLContext getSslContext()
- Returns:
- the sslContext, see
secure()in the builder doc
-
getMaxReconnect
public int getMaxReconnect()
- Returns:
- the maxReconnect attempts to make before failing, see
maxReconnects()in the builder doc
-
getReconnectWait
public java.time.Duration getReconnectWait()
- Returns:
- the reconnectWait, used between reconnect attempts to the same server, see
reconnectWait()in the builder doc
-
getConnectionTimeout
public java.time.Duration getConnectionTimeout()
- Returns:
- the connectionTimeout, see
connectionTimeout()in the builder doc
-
getPingInterval
public java.time.Duration getPingInterval()
- Returns:
- the pingInterval, see
pingInterval()in the builder doc
-
getRequestCleanupInterval
public java.time.Duration getRequestCleanupInterval()
- Returns:
- the request cleanup interval, see
requestCleanupInterval()in the builder doc
-
getMaxPingsOut
public int getMaxPingsOut()
- Returns:
- the maxPingsOut to limit the number of pings on the wire, see
maxPingsOut()in the builder doc
-
getReconnectBufferSize
public long getReconnectBufferSize()
- Returns:
- the reconnectBufferSize, to limit the amount of data held during
reconnection attempts, see
reconnectBufferSize()in the builder doc
-
getBufferSize
public int getBufferSize()
- Returns:
- the default size for buffers in the connection code, see
bufferSize()in the builder doc
-
getUsername
@Deprecated public java.lang.String getUsername()
Deprecated.converts the char array to a string, use getUserNameChars instead for more security- Returns:
- the username to use for basic authentication, see
userInfo()in the builder doc
-
getUsernameChars
public char[] getUsernameChars()
- Returns:
- the username to use for basic authentication, see
userInfo()in the builder doc
-
getPassword
@Deprecated public java.lang.String getPassword()
Deprecated.converts the char array to a string, use getPasswordChars instead for more security- Returns:
- the password the password to use for basic authentication, see
userInfo()in the builder doc
-
getPasswordChars
public char[] getPasswordChars()
- Returns:
- the password the password to use for basic authentication, see
userInfo()in the builder doc
-
getToken
@Deprecated public java.lang.String getToken()
Deprecated.converts the char array to a string, use getTokenChars instead for more security- Returns:
- the token to be used for token-based authentication, see
token()in the builder doc
-
getTokenChars
public char[] getTokenChars()
- Returns:
- the token to be used for token-based authentication, see
token()in the builder doc
-
isOldRequestStyle
public boolean isOldRequestStyle()
- Returns:
- the flag to turn on old style requests, see
oldStyleRequest()in the builder doc
-
getInboxPrefix
public java.lang.String getInboxPrefix()
- Returns:
- the inbox prefix to use for requests, see
inboxPrefix()in the builder doc
-
createURIForServer
public java.net.URI createURIForServer(java.lang.String serverURI) throws java.net.URISyntaxException- Throws:
java.net.URISyntaxException
-
buildProtocolConnectOptionsString
public java.nio.CharBuffer buildProtocolConnectOptionsString(java.lang.String serverURI, boolean includeAuth, byte[] nonce)Create the options string sent with a connect message. If includeAuth is true the auth information is included: If the server URIs have auth info it is used. Otherwise the userInfo is used.- Parameters:
serverURI- the current server uriincludeAuth- tells the options to build a connection string that includes auth informationnonce- if the client is supposed to sign the nonce for authentication- Returns:
- the options String, basically JSON
-
-