public interface Connection extends AutoCloseable
Connection object is a client's active connection to the STAN streaming data system.| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the connection.
|
io.nats.client.Connection |
getNatsConnection()
Returns the underlying NATS connection.
|
void |
publish(String subject,
byte[] data)
Publishes the payload specified by
data to the subject specified by subject,
and blocks until an ACK or error is returned. |
String |
publish(String subject,
byte[] data,
AckHandler ah)
Publishes the payload specified by
data to the subject specified by subject
and asynchronously processes the ACK or error state via the supplied AckHandler |
Subscription |
subscribe(String subject,
MessageHandler cb)
Creates a
Subscription with interest in a given subject, assigns the callback, and
immediately starts receiving messages. |
Subscription |
subscribe(String subject,
MessageHandler cb,
SubscriptionOptions opts)
Creates a
Subscription with interest in a given subject using the given
SubscriptionOptions, assigns the callback, and immediately starts receiving messages. |
Subscription |
subscribe(String subject,
String queue,
MessageHandler cb)
Creates a
Subscription in the queue group specified by queue with interest in
a given subject, assigns the message callback, and immediately starts receiving messages. |
Subscription |
subscribe(String subject,
String queue,
MessageHandler cb,
SubscriptionOptions opts)
Creates a
Subscription in the queue group specified by queue with interest in
a given subject, assigns the message callback, and immediately starts receiving messages. |
void publish(String subject, byte[] data) throws IOException
data to the subject specified by subject,
and blocks until an ACK or error is returned.subject - the subject to which the message is to be publisheddata - the message payloadIOException - if the publish operation is not successfulIllegalStateException - if the connection is closedString publish(String subject, byte[] data, AckHandler ah) throws IOException
data to the subject specified by subject
and asynchronously processes the ACK or error state via the supplied AckHandlersubject - the subject to which the message is to be publisheddata - the message payloadah - the AckHandler to invoke when an ack is received, passing the message GUID
and any error information.IOException - if an I/O exception is encounteredIllegalStateException - if the connection is closedAckHandlerSubscription subscribe(String subject, MessageHandler cb) throws IOException, TimeoutException
Subscription with interest in a given subject, assigns the callback, and
immediately starts receiving messages.subject - the subject of interestcb - a MessageHandler callback used to process messages received by the
SubscriptionSubscription objectIOException - if an I/O exception is encounteredTimeoutException - if the subscription request times outMessageHandler,
SubscriptionSubscription subscribe(String subject, MessageHandler cb, SubscriptionOptions opts) throws IOException, TimeoutException
Subscription with interest in a given subject using the given
SubscriptionOptions, assigns the callback, and immediately starts receiving messages.subject - the subject of interestcb - a MessageHandler callback used to process messages received by the
Subscriptionopts - the SubscriptionOptions to configure this SubscriptionSubscription objectIOException - if an I/O exception is encounteredTimeoutException - if the subscription request times outMessageHandler,
Subscription,
SubscriptionOptionsSubscription subscribe(String subject, String queue, MessageHandler cb) throws IOException, TimeoutException
Subscription in the queue group specified by queue with interest in
a given subject, assigns the message callback, and immediately starts receiving messages.subject - the subject of interestqueue - optional queue groupcb - a MessageHandler callback used to process messages received by the
SubscriptionSubscription objectIOException - if an I/O exception is encounteredTimeoutException - if the subscription request times outSubscription subscribe(String subject, String queue, MessageHandler cb, SubscriptionOptions opts) throws IOException, TimeoutException
Subscription in the queue group specified by queue with interest in
a given subject, assigns the message callback, and immediately starts receiving messages.subject - the subject of interestqueue - optional queue groupcb - a MessageHandler callback used to process messages received by the
Subscriptionopts - the SubscriptionOptions to configure for this SubscriptionSubscription objectIOException - if an I/O exception is encounteredTimeoutException - if the subscription request times outio.nats.client.Connection getNatsConnection()
Connectionvoid close()
throws IOException,
TimeoutException
close in interface AutoCloseableIOException - if an error occursTimeoutException - if the close request is not responded to within the timeout period.Copyright © 2016 Apcera, Inc.. All rights reserved.