public interface MessageClient
DistributedGroup facilitates messaging between instances and members of a group through
the message client. Message clients can be used to send publish-subscribe style messages to all members of a group
or direct messages to specific members of a group. Producers define how the cluster sends messages to consumers
through configurable MessageProducer.Options.
To create a producer, use one of the producer factory methods, passing the name of
a queue to which to produce messages. Message clients send messages to MessageServices, and queues are
local to each MessageService instance. Each member has a unique MessageService with a unique set
of queues.
MessageProducer<String> producer = group.messaging().producer("foo");
producer.send("Hello world!");
When a producer is created, a new instance of the producer is returned. A reference to the MessageProducer
instance must be retained for receiving responses and acks from the cluster.| Modifier and Type | Method and Description |
|---|---|
default <T> MessageProducer<T> |
producer(String name)
Returns a new named message producer.
|
<T> MessageProducer<T> |
producer(String name,
MessageProducer.Options options)
Returns a new named message producer.
|
default <T> MessageProducer<T> producer(String name)
The returned MessageProducer can be used to send messages to a queue of the provided name.
Named queues are local to the MessageService to which this client is connected. For example, if this
client belongs to a GroupMember then sending messages through the client will be sent
directly to the associated member and never to any other member. If the client belongs to a
DistributedGroup then messages can be sent to one or all members of the group depending
on the provided MessageProducer.Options.
The returned producer will be configured with default Options.
MessageProducer<String> producer = member.messaging().producer("foo");
producer.send("Hello world!");
T - The message type.name - The producer name.NullPointerException - if the producer name is null<T> MessageProducer<T> producer(String name, MessageProducer.Options options)
The returned MessageProducer can be used to send messages to a queue of the provided name.
Named queues are local to the MessageService to which this client is connected. For example, if this
client belongs to a GroupMember then sending messages through the client will be sent
directly to the associated member and never to any other member. If the client belongs to a
DistributedGroup then messages can be sent to one or all members of the group depending
on the provided MessageProducer.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
});
T - The message type.name - The producer name.options - The producer options.NullPointerException - if the producer name is nullMessageProducer.OptionsCopyright © 2013–2017. All rights reserved.