| Constructor and Description |
|---|
MockNats() |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes this Nats instance.
|
boolean |
isClosed()
Indicates if this client has been closed.
|
boolean |
isConnected()
Indicates if this client is connected to a NATS server.
|
void |
publish(String subject)
Publishes a message with an empty body to the specified subject.
|
Registration |
publish(String subject,
long period,
TimeUnit unit)
Publishes a message with an empty body to the specified subject on a recurring basis according to the specified
period.
|
void |
publish(String subject,
String body)
Publishes a message with the provided body to the specified subject.
|
Registration |
publish(String subject,
String body,
long period,
TimeUnit unit)
Publishes a message with the provided body to the specified subject on a recurring basis according to the
specified period.
|
void |
publish(String subject,
String body,
String replyTo)
Publishes a message with the provided body to the specified subject.
|
Registration |
publish(String subject,
String body,
String replyTo,
long period,
TimeUnit unit)
Publishes a message with the provided body to the specified subject on a recurring basis according to the
specified period.
|
Request |
request(String subject,
long timeout,
TimeUnit unit,
MessageHandler... messageHandlers)
Sends a request on the given subject.
|
Request |
request(String subject,
String message,
long timeout,
TimeUnit unit,
Integer maxReplies,
MessageHandler... messageHandlers)
Sends a request body on the given subject and will except a specified number of replies.
|
Request |
request(String subject,
String message,
long timeout,
TimeUnit unit,
MessageHandler... messageHandlers)
Sends a request body on the given subject.
|
Subscription |
subscribe(String subject,
Integer maxMessages,
MessageHandler... messageHandlers)
Subscribes to the specified subject and will automatically unsubscribe after the specified number of messages
arrives.
|
Subscription |
subscribe(String subject,
MessageHandler... messageHandlers)
Subscribes to the specified subject.
|
Subscription |
subscribe(String subject,
String queueGroup,
Integer maxMessages,
MessageHandler... messageHandlers)
Subscribes to the specified subject within a specific queue group and will automatically unsubscribe after the
specified number of messages arrives.
|
Subscription |
subscribe(String subject,
String queueGroup,
MessageHandler... messageHandlers)
Subscribes to the specified subject within a specific queue group.
|
public boolean isConnected()
Natsfalse after the
Nats.close() method has been invoked. If the connection to the server is lost, the client will automatically
try to reconnect to a server unless, of course, this feature has been disabled.isConnected in interface Natstrue if the client is connected to a NATS server, false otherwise.public boolean isClosed()
NatsisClosed in interface Natstrue if Nats.close() was called (explicitly or implicitly due to an error), false
otherwise.public void close()
Natspublic void publish(String subject)
NatsNats instance is not currently
connected to a NATS server, the message will be queued up to be published once a connection is established.public void publish(String subject, String body)
NatsNats instance is not
currently connected to a NATS server, the message will be queued up to be published once a connection is
established.public void publish(String subject, String body, String replyTo)
NatsNats instance is not currently connected to a NATS server, the
message will be queued up to be published once a connection is established.public Registration publish(String subject, long period, TimeUnit unit)
NatsNats instance is not currently connected to a NATS server, the message will not be sent
or queued up.public Registration publish(String subject, String body, long period, TimeUnit unit)
NatsNats instance is not currently connected to a NATS server, the message will
not be sent or queued up.publish in interface Natssubject - the subject to which the message will be publishedbody - the message body to publishperiod - the period between successive publishesunit - the time unit of the period parameterRegistration object that can be used to cancel recurring publishing.public Registration publish(String subject, String body, String replyTo, long period, TimeUnit unit)
NatsNats instance is not currently connected to a NATS server, the message will not be sent or queued up.publish in interface Natssubject - the subject to which the message will be publishedbody - the message body to publishreplyTo - the subject replies to this body should be sent to.period - the period between successive publishesunit - the time unit of the period parameterRegistration object that can be used to cancel recurring publishing.public Subscription subscribe(String subject, MessageHandler... messageHandlers)
Natssubscribe in interface Natssubject - the subject to subscribe tomessageHandlers - the MessageHandlers to listen for incoming messages.Subscription object used for interacting with the subscriptionNats.subscribe(String, String, Integer,MessageHandler...)public Subscription subscribe(String subject, String queueGroup, MessageHandler... messageHandlers)
Natssubscribe in interface Natssubject - the subject to subscribe toqueueGroup - the queue group the subscription participates inmessageHandlers - the MessageHandlers to listen for incoming messages.Subscription object used for interacting with the subscriptionNats.subscribe(String, String, Integer,MessageHandler...)public Subscription subscribe(String subject, Integer maxMessages, MessageHandler... messageHandlers)
Natssubscribe in interface Natssubject - the subject to subscribe tomaxMessages - the maximum number of messages received by the subscriptionmessageHandlers - the MessageHandlers to listen for incoming messagesSubscription object used for interacting with the subscriptionNats.subscribe(String, String, Integer,MessageHandler...)public Subscription subscribe(String subject, String queueGroup, Integer maxMessages, MessageHandler... messageHandlers)
NatsThe subject may contain wild cards. "*" matches any token, at any level of the subject. For example:
"foo.*.baz" matches "foo.bar.baz, foo.a.baz, etc.
"*.bar" matches "foo.bar", "baz.bar", etc.
"*.bar.*" matches "foo.bar.baz", "foo.bar.foo", etc.
">" matches any length of the tail of a subject and can only be the last token. For examples,
'foo.>' will match 'foo.bar', 'foo.bar.baz', 'foo.foo.bar.bax.22'. A subject of
simply ">" will match all messages.
All subscriptions with the same queueGroup will form a queue group. Each body will be delivered to
only one subscriber per queue group.
subscribe in interface Natssubject - the subject to subscribe toqueueGroup - the queue group the subscription participates inmaxMessages - the maximum number of messages received by the subscriptionmessageHandlers - the MessageHandlers to listen for incoming messages.Subscription object used for interacting with the subscriptionpublic Request request(String subject, long timeout, TimeUnit unit, MessageHandler... messageHandlers)
Natsrequest in interface Natssubject - the subject to send the request ontimeout - the amount of time to wait for repliesunit - the unit of time to waitmessageHandlers - the MessageHandlers to listen for incoming messages.Request instance associated with the request.Nats.request(String, String, long, java.util.concurrent.TimeUnit, Integer, MessageHandler...)public Request request(String subject, String message, long timeout, TimeUnit unit, MessageHandler... messageHandlers)
Natsrequest in interface Natssubject - the subject to send the request onmessage - the content of the requesttimeout - the amount of time to wait for repliesunit - the unit of time to waitmessageHandlers - the MessageHandlers to listen for incoming messages.Request instance associated with the request.Nats.request(String, String, long, java.util.concurrent.TimeUnit, Integer, MessageHandler...)public Request request(String subject, String message, long timeout, TimeUnit unit, Integer maxReplies, MessageHandler... messageHandlers)
NatsInvoking this method is roughly equivalent to the following:
String replyTo = Nats.createInbox();
Subscription subscription = nats.subscribe(replyTo, maxReplies);
Publication publication = nats.publish(subject, body, replyTo);
that returns a combination of Subscription and Publication as a Request object.
request in interface Natssubject - the subject to send the request onmessage - the content of the requesttimeout - the amount of time to wait for repliesunit - the unit of time to waitmaxReplies - the maximum number of replies that the request will accept before automatically closing,
null for unlimited repliesmessageHandlers - the MessageHandlers to listen for incoming messages.Request instance associated with the request.Copyright © 2015. All Rights Reserved.