public interface Connection
Connection
object is a client's active connection to NATS.Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the connection, also closing all subscriptions on this connection.
|
void |
flush()
Flushes the current connection, waiting up to 60 seconds for completion.
|
void |
flush(int timeout)
Flushes the current connection, waiting up to
timeout for successful completion. |
ClosedCallback |
getClosedCallback()
Returns the connection closed callback.
|
String |
getConnectedServerId()
Returns the unique server ID string of the connected server.
|
io.nats.client.ServerInfo |
getConnectedServerInfo()
Returns the details from the INFO protocol message received.
|
String |
getConnectedUrl()
Returns the URL string of the currently connected NATS server.
|
DisconnectedCallback |
getDisconnectedCallback()
Returns the connection disconnected callback.
|
ExceptionHandler |
getExceptionHandler()
Returns the connection's asynchronous exception callback.
|
Exception |
getLastException()
Returns the last exception registered on the connection.
|
long |
getMaxPayload()
Gets the maximum payload size this connection will accept.
|
int |
getPendingByteCount()
Returns the number of valid bytes in the pending output buffer.
|
ReconnectedCallback |
getReconnectedCallback()
Returns the connection reconnected callback.
|
Constants.ConnState |
getState()
Returns the current connection state.
|
Statistics |
getStats()
Retrieves the connection statistics.
|
boolean |
isClosed()
Indicates whether the connection has been closed.
|
boolean |
isConnected()
Indicates whether the connection is currently reconnecting.
|
boolean |
isReconnecting()
Indicates whether the connection is currently reconnecting.
|
String |
newInbox()
Creates a new, uniquely named inbox with the prefix '_INBOX.'
|
void |
publish(Message msg)
Publishes a message to a subject.
|
void |
publish(String subject,
byte[] data)
Publishes the payload specified by
data to the subject specified by subject . |
void |
publish(String subject,
String reply,
byte[] data)
Publishes the payload specified by
data to the subject specified by subject ,
with an optional reply subject. |
void |
publish(String subject,
String reply,
byte[] data,
boolean flush)
Publishes the payload specified by
data to the subject specified by subject ,
with an optional reply subject. |
Message |
request(String subject,
byte[] data)
Publishes a request message to the specified subject, waiting for a response until one is
available.
|
Message |
request(String subject,
byte[] data,
long timeout)
Publishes a request message to the specified subject, waiting up to
timeout msec for
a response. |
Message |
request(String subject,
byte[] data,
long timeout,
TimeUnit unit) |
void |
resetStats()
Resets the gathered statistics for this connection.
|
void |
setClosedCallback(ClosedCallback cb)
Sets the connection closed callback.
|
void |
setDisconnectedCallback(DisconnectedCallback cb)
Sets the connection disconnected callback.
|
void |
setExceptionHandler(ExceptionHandler exceptionHandler)
Sets the connection's asynchronous exception callback.
|
void |
setReconnectedCallback(ReconnectedCallback cb)
Sets the connection reconnected callback.
|
SyncSubscription |
subscribe(String subject)
Creates a
SyncSubscription with interest in a given subject. |
AsyncSubscription |
subscribe(String subject,
MessageHandler cb)
Creates a
AsyncSubscription with interest in a given subject, assign the callback,
and immediately start receiving messages |
SyncSubscription |
subscribe(String subject,
String queue)
Creates a
SyncSubscription with interest in a given subject. |
AsyncSubscription |
subscribe(String subject,
String queue,
MessageHandler cb)
Creates an asynchronous queue subscriber on a given subject of interest.
|
AsyncSubscription |
subscribeAsync(String subject,
MessageHandler cb)
Deprecated.
As of release 0.6, use
subscribe(String, MessageHandler) instead |
AsyncSubscription |
subscribeAsync(String subject,
String queue,
MessageHandler cb)
Deprecated.
As of release 0.6, use
subscribe(String, String, MessageHandler) instead |
SyncSubscription |
subscribeSync(String subject)
Creates a
SyncSubscription with interest in a given subject. |
SyncSubscription |
subscribeSync(String subject,
String queue)
Creates a synchronous queue subscriber on a given subject of interest.
|
void publish(String subject, byte[] data) throws IOException
data
to the subject specified by subject
.subject
- the subject to publish the message todata
- the message payloadIOException
- if an I/O error is encounteredvoid publish(Message msg) throws IOException
Message.setSubject(String)
or the Message.Message(String, String, byte[])
constructor.msg
- the Message
to publishIOException
- if an I/O error is encounteredvoid publish(String subject, String reply, byte[] data) throws IOException
data
to the subject specified by subject
,
with an optional reply subject. If reply
is null
, the behavior is identical
to publish(String, byte[])
subject
- the subject to publish the message toreply
- the subject to which subscribers should send responsesdata
- the message payloadIOException
- if an I/O error is encounteredvoid publish(String subject, String reply, byte[] data, boolean flush) throws IOException
data
to the subject specified by subject
,
with an optional reply subject. If reply
is null
, the behavior is identical
to publish(String, byte[])
. if flush
is true
, a flush of the
Connection's output stream will be forced.subject
- the subject to publish the message toreply
- the subject to which subscribers should send responsesdata
- the message payloadflush
- whether to force a flush of the output streamIOException
- if an I/O error is encounteredMessage request(String subject, byte[] data, long timeout) throws TimeoutException, IOException
timeout
msec for
a response.subject
- the subject to publish the request message todata
- the request message payloadtimeout
- how long to wait for a response message (in msec)IOException
- if a connection-related error occursTimeoutException
- if timeout
elapses before a message is returnedMessage request(String subject, byte[] data) throws TimeoutException, IOException
subject
- the subject to publish the request message todata
- the message payloadIOException
- if a connection-related error occursTimeoutException
- if timeout
elapses before a message is returnedMessage request(String subject, byte[] data, long timeout, TimeUnit unit) throws TimeoutException, IOException
TimeoutException
IOException
SyncSubscription subscribe(String subject)
SyncSubscription
with interest in a given subject. In order to receive
messages, call one of the available SyncSubscription.nextMessage()
.subject
- the subject of interestSyncSubscription
IllegalArgumentException
- if the subject name contains illegal characters.NullPointerException
- if the subject name is nullIllegalStateException
- if the connection is closedSyncSubscription subscribe(String subject, String queue)
SyncSubscription
with interest in a given subject. All subscribers with the
same queue name will form the queue group and only one member of the group will be selected
to receive any given message.subject
- the subject of interestqueue
- the queue groupSyncSubscription
IllegalArgumentException
- if the subject (or queue) name contains illegal characters.NullPointerException
- if the subject name is nullIllegalStateException
- if the connection is closedAsyncSubscription subscribe(String subject, MessageHandler cb)
AsyncSubscription
with interest in a given subject, assign the callback,
and immediately start receiving messagessubject
- the subject of interestcb
- a MessageHandler
object used to process messages received by the
AsyncSubscription
AsyncSubscription
IllegalArgumentException
- if the subject (or queue) name contains illegal characters.NullPointerException
- if the subject name is nullIllegalStateException
- if the connection is closedAsyncSubscription subscribe(String subject, String queue, MessageHandler cb)
subject
- the subject of interestqueue
- the name of the queue groupcb
- a MessageHandler
object used to process messages received by the
Subscription
Subscription
AsyncSubscription subscribeAsync(String subject, MessageHandler cb)
subscribe(String, MessageHandler)
insteadAsyncSubscription
with interest in a given subject, assign the callback,
and immediately start receiving messagessubject
- the subject of interestcb
- a MessageHandler
object used to process messages received by the
AsyncSubscription
AsyncSubscription
IllegalArgumentException
- if the subject (or queue) name contains illegal characters.NullPointerException
- if the subject name is nullIllegalStateException
- if the connection is closedAsyncSubscription subscribeAsync(String subject, String queue, MessageHandler cb)
subscribe(String, String, MessageHandler)
insteadAsyncSubscription
with interest in a given subject, assign the message
callback, and immediately start receiving messages.subject
- the subject of interestqueue
- the name of the queue groupcb
- a message callback for this subscriptionAsyncSubscription
IllegalArgumentException
- if the subject (or queue) name contains illegal characters.NullPointerException
- if the subject name is nullIllegalStateException
- if the connection is closedSyncSubscription subscribeSync(String subject, String queue)
MessageHandler
must be registered, and
AsyncSubscription.start()
must be called.subject
- the subject of interestqueue
- the queue groupSyncSubscription
IllegalArgumentException
- if the subject (or queue) name contains illegal characters.NullPointerException
- if the subject name is nullIllegalStateException
- if the connection is closedSyncSubscription subscribeSync(String subject)
SyncSubscription
with interest in a given subject. In order to receive
messages, call one of the available SyncSubscription.nextMessage()
.subject
- the subject of interestSyncSubscription
IllegalArgumentException
- if the subject name contains illegal characters.NullPointerException
- if the subject name is nullIllegalStateException
- if the connection is closedString newInbox()
void close()
When close()
is called, the following things happen, in order:
close
in interface AutoCloseable
AutoCloseable.close()
boolean isClosed()
boolean isConnected()
boolean isReconnecting()
Statistics getStats()
Statistics
void resetStats()
Statistics
long getMaxPayload()
void flush(int timeout) throws IOException, TimeoutException, Exception
timeout
for successful completion.timeout
- - the connection timeout in milliseconds.IOException
- if a connection-related error prevents the flush from completingTimeoutException
- if the connection does not complete within the specified intervalException
- if some other error occursvoid flush() throws IOException, Exception
IOException
- if a connection-related issue prevented the flush from completing
successfullyException
- if some other error is encounteredflush(int)
ExceptionHandler getExceptionHandler()
ExceptionHandler
void setExceptionHandler(ExceptionHandler exceptionHandler)
exceptionHandler
- the asynchronous exception handler to set for this connectionExceptionHandler
ClosedCallback getClosedCallback()
ClosedCallback
void setClosedCallback(ClosedCallback cb)
cb
- the connection closed callback to setDisconnectedCallback getDisconnectedCallback()
void setDisconnectedCallback(DisconnectedCallback cb)
cb
- the disconnected callback to setReconnectedCallback getReconnectedCallback()
void setReconnectedCallback(ReconnectedCallback cb)
cb
- the reconnect callback to set for this connectionString getConnectedUrl()
String getConnectedServerId()
Constants.ConnState getState()
Constants.ConnState
io.nats.client.ServerInfo getConnectedServerInfo()
ServerInfo
Exception getLastException()
int getPendingByteCount()
Copyright © 2015–2016 Apcera, Inc.. All rights reserved.