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 |
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. |
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.
|
AsyncSubscription |
subscribe(String subject,
MessageHandler cb)
Creates a
AsyncSubscription with interest in a given subject, assign the callback,
and immediately start receiving messages |
Subscription |
subscribe(String subject,
String queue,
MessageHandler cb)
Creates an asynchronous queue subscriber on a given subject of interest.
|
AsyncSubscription |
subscribeAsync(String subject)
Creates a
AsyncSubscription with interest in a given subject. |
AsyncSubscription |
subscribeAsync(String subject,
MessageHandler cb)
Creates a
AsyncSubscription with interest in a given subject, assign the callback,
and immediately start receiving messages |
AsyncSubscription |
subscribeAsync(String subject,
String queue)
Creates an asynchronous queue subscriber on a given subject of interest.
|
AsyncSubscription |
subscribeAsync(String subject,
String queue,
MessageHandler cb)
Create an
AsyncSubscription with interest in a given subject, assign the message
callback, and immediately start receiving messages. |
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 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
TimeoutExceptionIOExceptionAsyncSubscription 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
AsyncSubscriptionAsyncSubscriptionIllegalArgumentException - if the subject (or queue) name contains illegal characters.NullPointerException - if the subject name is nullIllegalStateException - if the connection is closedSubscription 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
SubscriptionSubscriptionAsyncSubscription subscribeAsync(String subject)
AsyncSubscription with interest in a given subject. In order to receive
messages, a MessageHandler must be registered, and AsyncSubscription.start()
must be called.subject - the subject of interestAsyncSubscriptionIllegalArgumentException - if the subject name contains illegal characters.NullPointerException - if the subject name is nullIllegalStateException - if the connection is closedAsyncSubscription subscribeAsync(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
AsyncSubscriptionAsyncSubscriptionIllegalArgumentException - 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
must be registered, and AsyncSubscription.start() must be called.subject - the subject of interestqueue - the name of the queue groupSubscriptionIllegalArgumentException - 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)
AsyncSubscription 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 subscriptionAsyncSubscriptionIllegalArgumentException - 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 groupSyncSubscriptionIllegalArgumentException - 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 interestSyncSubscriptionIllegalArgumentException - 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 AutoCloseableAutoCloseable.close()boolean isClosed()
boolean isReconnecting()
Statistics getStats()
Statisticsvoid resetStats()
Statisticslong 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()
ExceptionHandlervoid setExceptionHandler(ExceptionHandler exceptionHandler)
exceptionHandler - the asynchronous exception handler to set for this connectionExceptionHandlerClosedCallback getClosedCallback()
ClosedCallbackvoid 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.ConnStateio.nats.client.ServerInfo getConnectedServerInfo()
ServerInfoException getLastException()
int getPendingByteCount()
Copyright © 2015–2016 Apcera, Inc.. All rights reserved.