public interface MessageConsumer<T> extends AutoCloseable
Consumers receive messages sent by MessageProducers to specific named queues. Messages are
pushed to consumers through Copycat's session event protocol.
To listen for messages received by a consumer, register a message listener via the onMessage(Consumer)
method:
MessageConsumer<String> consumer = localMember.messaging().consumer("foo");
consumer.onMessage(message -> {
// ...
message.ack();
});
Consumer callbacks will be called with a unique Message object. Each message consumed by a consumer
is guaranteed to have a unique Message.id(). It is the responsibility of every consumer to either
ack or reply to every message. Failure to ack or reply
to a message will result in a memory leak and the failure to publish messages to a member.| Modifier and Type | Interface and Description |
|---|---|
static class |
MessageConsumer.Options
Message consumer options.
|
| Modifier and Type | Method and Description |
|---|---|
default void |
close()
Closes the consumer.
|
Listener<Message<T>> |
onMessage(Consumer<Message<T>> callback)
Registers a listener for messages received by the consumer.
|
Listener<Message<T>> onMessage(Consumer<Message<T>> callback)
Messages are received by consumers through Copycat's session event protocol. Each message is guaranteed
to be received by the consumer on the same thread, and consumed Messages are guaranteed to have
unique ids. It is the responsibility of every consumer to either ack
or reply to every message. Failure to ack or reply to a message will result
in a memory leak and the failure to publish messages to a member.
callback - The message listener callback.NullPointerException - if the listener callback is nulldefault void close()
When the consumer is closed, the consumer will be removed from the list of consumers for the parent
MessageService and messages will no longer be delivered to this consumer.
close in interface AutoCloseableCopyright © 2013–2017. All rights reserved.