public interface MessageProducer<T> extends AutoCloseable
MessageService queue.
Producers facilitate sending messages to remote queues through the Atomix cluster. Producers can be used to broadcast messages to entire groups or send direct messages to random or specific members of a group. Messages can be sent synchronously or asynchronously, or producers can await replies from consumers.
When messages are sent by a producer to consumers, they're sent through the Atomix cluster as writes to the group's replicated state machine. Messages are enqueued in memory on each stateful server in the cluster until received and acknowledged by the appropriate consumers.
To configure a message producer, the producer must be constructed with
Options.
MessageProducer.Options options = new MessageProducer.Options()
.withExecution(MessageProducer.Execution.ASYNC)
.withDelivery(MessageProducer.Delivery.RANDOM);
MessageProducer<String> producer = group.messaging().producer("foo");
producer.send("Hello world!").thenRun(() -> {
// Message was stored to the cluster
});
The configured Execution defines the criteria for
completion of messages sent by a producer.
SYNC producers send messages to consumers
and await acknowledgement from the consumer side of the queue. If a producer is producing to an entire group,
synchronous producers will await acknowledgement from all members of the group.ASYNC producers await acknowledgement of
persistence in the cluster but not acknowledgement that messages have been received and processed by consumers.REQUEST_REPLY producers await
arbitrary responses from all consumers to which a message is sent. If a message is sent to a group of consumers,
message reply futures will be completed with a list of reply values.Delivery defines how messages are delivered
to consumers, particularly when the producer is sending messages to a group.
DIRECT producers send messages directly to
specific group members. This option applies only to producers constructed from GroupMember
messaging clients.MessageProducer.Delivery.RANDOM producers send each message to a random
member of the group. In the event that a message is not successfully acknowledged by a
member and that member fails or leaves the group, random messages will be redelivered to remaining members
of the group.MessageProducer.Delivery.BROADCAST producers send messages to all available
members of a group. This option applies only to producers constructed from DistributedGroup
messaging clients.| Modifier and Type | Interface and Description |
|---|---|
static class |
MessageProducer.Delivery
Delivery policy for defining how messages are delivered to consumers, particularly when producing messages to
a group.
|
static class |
MessageProducer.Execution
Execution policy for defining the criteria for completion of a message produced by a producer.
|
static class |
MessageProducer.Options
Message producer options.
|
| Modifier and Type | Method and Description |
|---|---|
default void |
close()
Closes the producer.
|
<U> CompletableFuture<U> |
send(T message)
Sends a message.
|
<U> CompletableFuture<U> send(T message)
The behavior of the queue when sending a message is defined by the configured producer
Options. All messages when sent by a producer are
committed as writes to the Atomix cluster, but the returned CompletableFuture will be completed based
on the configured Execution and
Delivery policies.
MessageProducer.Options options = new MessageProducer.Options()
.withExecution(Execution.SYNC);
MessageProducer<String> producer = member.messaging().producer("foo");
producer.send("Hello world!").thenRun(() -> {
// Consumer acknowledged the message
});
message - The message to send.default void close()
close in interface AutoCloseableCopyright © 2013–2017. All rights reserved.