public interface Message<T>
Messages are sent by DistributedGroup users to any member of a group.
Messages are replicated and persisted within the Atomix cluster before being pushed to clients on a queue. Once a message
is received by a message listener, the message may be processed asynchronously and either acknowledged or
failed once processing is complete.
DistributedGroup group = atomix.getGroup("message-group").get();
group.join().thenAccept(member -> {
MessageConsumer<String> consumer = member.messaging().consumer("foo");
consumer.onMessage(message -> {
processTask(message).thenRun(() -> {
message.ack();
});
});
});
Consumers may also send replies to messages. To send a reply, use the reply(Object) method. Note that
replies may or may not be received by producers depending on their configuration. Producers must specify support
for the REQUEST_REPLY execution policy
to receive replies.
consumer.onMessage(message -> {
message.reply("Hello world!");
});
| Modifier and Type | Method and Description |
|---|---|
CompletableFuture<Void> |
ack()
Acknowledges completion of the message.
|
CompletableFuture<Void> |
fail()
Fails processing of the message.
|
long |
id()
Returns the message ID.
|
T |
message()
Returns the message value.
|
CompletableFuture<Void> |
reply(Object message)
Replies to the message.
|
long id()
The message ID is guaranteed to be unique and monotonically increasing within a given message queue. Tasks received across members are not associated with one another.
T message()
This is the value that was submitted by the sending process.
CompletableFuture<Void> reply(Object message)
Replies are sent through the Atomix cluster as a write operation. Users can await the completion of the underlying
write operation through the returned CompletableFuture.
message - The reply message.CompletableFuture<Void> ack()
Once a message is acknowledged, an ack will be sent back to the process that submitted the message. Acknowledging completion of a message does not guarantee that the sender will learn of the acknowledgement. The acknowledgement itself may fail to reach the cluster or the sender may crash before the acknowledgement can be received. Acks serve only as positive acknowledgement, but the lack of an ack does not indicate failure.
CompletableFuture<Void> fail()
Once a message is failed, a failure message will be sent back to the process that submitted the message for processing. Failing a message does not guarantee that the sender will learn of the failure. The process that submitted the message may itself fail.
Copyright © 2013–2017. All rights reserved.