public class DefaultSubscription extends Object implements Subscription
Subscription interface.| Modifier | Constructor and Description |
|---|---|
protected |
DefaultSubscription(String subject,
String queueGroup,
Integer maxMessages,
MessageHandler... messageHandlers) |
| Modifier and Type | Method and Description |
|---|---|
Registration |
addMessageHandler(MessageHandler messageHandler)
Registers a
MessageHandler instance with this subscription that will be invoked every time the
subscription receives a message. |
void |
close()
Closes this subscription.
|
protected Message |
createMessage(String subject,
String body,
String queueGroup,
String replyTo) |
Integer |
getMaxMessages()
Returns the maximum number of messages this subscription will receive before being closed automatically.
|
String |
getQueueGroup()
Returns the queue group the subscription is participating in.
|
int |
getReceivedMessages()
Returns the number of messages this subscription has received.
|
String |
getSubject()
Returns this subscription's NATS subject.
|
MessageIterator |
iterator()
Creates a
MessageIterator that can be used for fetching messages from this subscription in a
blocking manner. |
void |
onMessage(String subject,
String body,
String replyTo,
Executor executor) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEach, spliteratorprotected DefaultSubscription(String subject, String queueGroup, Integer maxMessages, MessageHandler... messageHandlers)
public void close()
SubscriptionMessageHandler objects associated with this request will no longer receive
messages for this subscription after this method is invoked. All MessageIterator objects created by
this subscription will also be closed.close in interface AutoCloseableclose in interface Subscriptionpublic String getSubject()
SubscriptiongetSubject in interface Subscriptionpublic Registration addMessageHandler(MessageHandler messageHandler)
SubscriptionMessageHandler instance with this subscription that will be invoked every time the
subscription receives a message.addMessageHandler in interface SubscriptionmessageHandler - the message handler that is invoked when a message arrivespublic MessageIterator iterator()
SubscriptionMessageIterator that can be used for fetching messages from this subscription in a
blocking manner. Because Subscription implements the Iterable interface, a subscription can be
used in a Java for loop. For example:
for (Message message : nats.subscribe("foo.>") {
System.out.println(message);
}
The for loop may terminate with an exception when the subscription is closed.iterator in interface Iterable<Message>iterator in interface SubscriptionMessageIteratorpublic int getReceivedMessages()
SubscriptiongetReceivedMessages in interface Subscriptionpublic Integer getMaxMessages()
SubscriptiongetMaxMessages in interface Subscriptionnull if no maximum was specified.public String getQueueGroup()
SubscriptiongetQueueGroup in interface SubscriptionCopyright © 2015. All Rights Reserved.