public interface StreamingConnection
extends java.lang.AutoCloseable
StreamingConnection
object is a client's active connection to the nats 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(java.lang.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. |
java.lang.String |
publish(java.lang.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
If the underlying NATs connection is disconnected, due to network problems, messages will not flow until
that connection is re-established. |
Subscription |
subscribe(java.lang.String subject,
MessageHandler cb)
Creates a
Subscription with interest in a given subject, assigns the callback, and
immediately starts receiving messages. |
Subscription |
subscribe(java.lang.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(java.lang.String subject,
java.lang.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(java.lang.String subject,
java.lang.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(java.lang.String subject, byte[] data) throws java.io.IOException, java.lang.InterruptedException, java.util.concurrent.TimeoutException
data
to the subject specified by subject
,
and blocks until an ACK or error is returned.
If the underlying NATs connection is disconnected, due to network problems, messages will not flow until
that connection is re-established. The underlying connection will batch published messages until the reconnect
buffer is full. See the JavaDoc for Options in the NATs client for more information on the reconnect buffer.
However, keep in mind that ACK timeouts can come in to play and result in an exception despite the underlying connections
caching attempt.subject
- the subject to which the message is to be publisheddata
- the message payloadjava.io.IOException
- if the publish operation is not successfuljava.lang.InterruptedException
- if the calling thread is interrupted before the call completesjava.lang.IllegalStateException
- if the connection is closedjava.util.concurrent.TimeoutException
- if there is a timeout trying to ackjava.lang.String publish(java.lang.String subject, byte[] data, AckHandler ah) throws java.io.IOException, java.lang.InterruptedException, java.util.concurrent.TimeoutException
data
to the subject specified by subject
and asynchronously processes the ACK or error state via the supplied AckHandler
If the underlying NATs connection is disconnected, due to network problems, messages will not flow until
that connection is re-established. The underlying connection will batch published messages until the reconnect
buffer is full. See the JavaDoc for Options in the NATs client for more information on the reconnect buffer.
However, keep in mind that ACK timeouts can come in to play and result in an exception despite the underlying connections
caching attempt.subject
- 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.java.io.IOException
- if an I/O exception is encounteredjava.lang.InterruptedException
- if the calling thread is interrupted before the call completesjava.lang.IllegalStateException
- if the connection is closedjava.util.concurrent.TimeoutException
- if there is a timeout trying to ackAckHandler
Subscription subscribe(java.lang.String subject, MessageHandler cb) throws java.io.IOException, java.lang.InterruptedException, java.util.concurrent.TimeoutException
Subscription
with interest in a given subject, assigns the callback, and
immediately starts receiving messages.
If the underlying NATs connection is disconnected, due to network problems, messages will not flow until
that connection is re-established. That includes telling the server about the subscription. In that
situation it is possible for a timeout to occur.subject
- the subject of interestcb
- a MessageHandler
callback used to process messages received by the
Subscription
Subscription
object, or null if the subscription request timed outjava.io.IOException
- if an I/O exception is encounteredjava.lang.InterruptedException
- if the calling thread is interrupted before the call completesjava.util.concurrent.TimeoutException
- if the server request cannot complete within subscription timeoutMessageHandler
,
Subscription
Subscription subscribe(java.lang.String subject, MessageHandler cb, SubscriptionOptions opts) throws java.io.IOException, java.lang.InterruptedException, java.util.concurrent.TimeoutException
Subscription
with interest in a given subject using the given
SubscriptionOptions
, assigns the callback, and immediately starts receiving messages.
If the underlying NATs connection is disconnected, due to network problems, messages will not flow until
that connection is re-established. That includes telling the server about the subscription. In that
situation it is possible for a timeout to occur.subject
- the subject of interestcb
- a MessageHandler
callback used to process messages received by the
Subscription
opts
- the SubscriptionOptions
to configure this Subscription
Subscription
object, or null if the subscription request timed outjava.io.IOException
- if an I/O exception is encounteredjava.lang.InterruptedException
- if the calling thread is interrupted before the call completesjava.util.concurrent.TimeoutException
- if the server request cannot complete within subscription timeoutMessageHandler
,
Subscription
,
SubscriptionOptions
Subscription subscribe(java.lang.String subject, java.lang.String queue, MessageHandler cb) throws java.io.IOException, java.lang.InterruptedException, java.util.concurrent.TimeoutException
Subscription
in the queue group specified by queue
with interest in
a given subject, assigns the message callback, and immediately starts receiving messages.
If the underlying NATs connection is disconnected, due to network problems, messages will not flow until
that connection is re-established. That includes telling the server about the subscription. In that
situation it is possible for a timeout to occur.subject
- the subject of interestqueue
- optional queue groupcb
- a MessageHandler
callback used to process messages received by the
Subscription
Subscription
object, or null if the subscription request timed outjava.io.IOException
- if an I/O exception is encounteredjava.lang.InterruptedException
- if the calling thread is interrupted before the call completesjava.util.concurrent.TimeoutException
- if the server request cannot complete within subscription timeoutSubscription subscribe(java.lang.String subject, java.lang.String queue, MessageHandler cb, SubscriptionOptions opts) throws java.io.IOException, java.lang.InterruptedException, java.util.concurrent.TimeoutException
Subscription
in the queue group specified by queue
with interest in
a given subject, assigns the message callback, and immediately starts receiving messages.
If the underlying NATs connection is disconnected, due to network problems, messages will not flow until
that connection is re-established. That includes telling the server about the subscription. In that
situation it is possible for a timeout to occur.subject
- the subject of interestqueue
- optional queue groupcb
- a MessageHandler
callback used to process messages received by the
Subscription
opts
- the SubscriptionOptions
to configure for this Subscription
Subscription
object, or null if the subscription request timed outjava.io.IOException
- if an I/O exception is encounteredjava.lang.InterruptedException
- if the calling thread is interrupted before the call completesjava.util.concurrent.TimeoutException
- if the server request cannot complete within subscription timeoutio.nats.client.Connection getNatsConnection()
Connection
void close() throws java.io.IOException, java.util.concurrent.TimeoutException, java.lang.InterruptedException
close
in interface java.lang.AutoCloseable
java.io.IOException
- if an error occursjava.util.concurrent.TimeoutException
- if the close request is not responded to within the timeout period.java.lang.InterruptedException