Package io.atomix.cluster.messaging
Interface ClusterCommunicationService
- All Known Subinterfaces:
ManagedClusterCommunicationService
public interface ClusterCommunicationService
High-level
MemberId based intra-cluster messaging service.
The cluster communication service is used for high-level communication between cluster members. Messages are sent
and received based on arbitrary String message subjects. Direct messages are sent using the MemberId
to which to send the message. This API supports several types of messaging:
broadcast(String, Object)broadcasts a message to all cluster membersmulticast(String, Object, Set)sends the message to all provided membersunicast(String, Object, MemberId)sends a unicast message directly to the given membersend(String, Object, MemberId)sends a message directly to the given member and awaits a reply
subscribe(String, Consumer, Executor) methods:
atomix.getCommunicationService().subscribe("test", message -> {
System.out.println("Received message");
}, executor);
-
Method Summary
Modifier and Type Method Description default <M> voidbroadcast(String subject, M message)Broadcasts a message to all members.default <M> voidbroadcast(String subject, M message, boolean reliable)Broadcasts a message to all members.default <M> voidbroadcast(String subject, M message, java.util.function.Function<M,byte[]> encoder)Broadcasts a message to all members.<M> voidbroadcast(String subject, M message, java.util.function.Function<M,byte[]> encoder, boolean reliable)Broadcasts a message to all members.default <M> voidbroadcastIncludeSelf(String subject, M message)Broadcasts a message to all members over TCP including self.default <M> voidbroadcastIncludeSelf(String subject, M message, boolean reliable)Broadcasts a message to all members including self.default <M> voidbroadcastIncludeSelf(String subject, M message, java.util.function.Function<M,byte[]> encoder)Broadcasts a message to all members over TCP including self.<M> voidbroadcastIncludeSelf(String subject, M message, java.util.function.Function<M,byte[]> encoder, boolean reliable)Broadcasts a message to all members including self.default <M> voidmulticast(String subject, M message, java.util.function.Function<M,byte[]> encoder, Set<MemberId> memberIds)Multicasts a message to a set of members over TCP.<M> voidmulticast(String subject, M message, java.util.function.Function<M,byte[]> encoder, Set<MemberId> memberIds, boolean reliable)Multicasts a message to a set of members.default <M> voidmulticast(String subject, M message, Set<MemberId> memberIds)Multicasts a message to a set of members over TCP.default <M> voidmulticast(String subject, M message, Set<MemberId> memberIds, boolean reliable)Multicasts a message to a set of members.default <M, R> CompletableFuture<R>send(String subject, M message, MemberId toMemberId)Sends a message and expects a reply.default <M, R> CompletableFuture<R>send(String subject, M message, MemberId toMemberId, java.time.Duration timeout)Sends a message and expects a reply.default <M, R> CompletableFuture<R>send(String subject, M message, java.util.function.Function<M,byte[]> encoder, java.util.function.Function<byte[],R> decoder, MemberId toMemberId)Sends a message and expects a reply.<M, R> CompletableFuture<R>send(String subject, M message, java.util.function.Function<M,byte[]> encoder, java.util.function.Function<byte[],R> decoder, MemberId toMemberId, java.time.Duration timeout)Sends a message and expects a reply.default <M> CompletableFuture<Void>subscribe(String subject, java.util.function.BiConsumer<MemberId,M> handler, Executor executor)Adds a new subscriber for the specified message subject.default <M> CompletableFuture<Void>subscribe(String subject, java.util.function.Consumer<M> handler, Executor executor)Adds a new subscriber for the specified message subject.<M> CompletableFuture<Void>subscribe(String subject, java.util.function.Function<byte[],M> decoder, java.util.function.BiConsumer<MemberId,M> handler, Executor executor)Adds a new subscriber for the specified message subject.<M> CompletableFuture<Void>subscribe(String subject, java.util.function.Function<byte[],M> decoder, java.util.function.Consumer<M> handler, Executor executor)Adds a new subscriber for the specified message subject.<M, R> CompletableFuture<Void>subscribe(String subject, java.util.function.Function<byte[],M> decoder, java.util.function.Function<M,CompletableFuture<R>> handler, java.util.function.Function<R,byte[]> encoder)Adds a new subscriber for the specified message subject.<M, R> CompletableFuture<Void>subscribe(String subject, java.util.function.Function<byte[],M> decoder, java.util.function.Function<M,R> handler, java.util.function.Function<R,byte[]> encoder, Executor executor)Adds a new subscriber for the specified message subject.default <M, R> CompletableFuture<Void>subscribe(String subject, java.util.function.Function<M,CompletableFuture<R>> handler)Adds a new subscriber for the specified message subject.default <M, R> CompletableFuture<Void>subscribe(String subject, java.util.function.Function<M,R> handler, Executor executor)Adds a new subscriber for the specified message subject.default <M> CompletableFuture<Void>unicast(String subject, M message, MemberId toMemberId)Sends a message to the specified member over TCP.default <M> CompletableFuture<Void>unicast(String subject, M message, MemberId toMemberId, boolean reliable)Sends a message to the specified member.default <M> CompletableFuture<Void>unicast(String subject, M message, java.util.function.Function<M,byte[]> encoder, MemberId toMemberId)Sends a message to the specified member over TCP.<M> CompletableFuture<Void>unicast(String subject, M message, java.util.function.Function<M,byte[]> encoder, MemberId toMemberId, boolean reliable)Sends a message to the specified member.voidunsubscribe(String subject)Removes a subscriber for the specified message subject.
-
Method Details
-
broadcast
Broadcasts a message to all members.- Type Parameters:
M- message type- Parameters:
subject- message subjectmessage- message to send
-
broadcast
Broadcasts a message to all members.- Type Parameters:
M- message type- Parameters:
subject- message subjectmessage- message to sendreliable- whether to perform a reliable (TCP) unicast
-
broadcast
default <M> void broadcast(String subject, M message, java.util.function.Function<M,byte[]> encoder)Broadcasts a message to all members.- Type Parameters:
M- message type- Parameters:
subject- message subjectmessage- message to sendencoder- function for encoding message to byte[]
-
broadcast
<M> void broadcast(String subject, M message, java.util.function.Function<M,byte[]> encoder, boolean reliable)Broadcasts a message to all members.- Type Parameters:
M- message type- Parameters:
subject- message subjectmessage- message to sendencoder- function for encoding message to byte[]reliable- whether to perform a reliable (TCP) unicast
-
broadcastIncludeSelf
Broadcasts a message to all members over TCP including self.- Type Parameters:
M- message type- Parameters:
subject- message subjectmessage- message to send
-
broadcastIncludeSelf
Broadcasts a message to all members including self.- Type Parameters:
M- message type- Parameters:
subject- message subjectmessage- message to sendreliable- whether to perform a reliable (TCP) unicast
-
broadcastIncludeSelf
default <M> void broadcastIncludeSelf(String subject, M message, java.util.function.Function<M,byte[]> encoder)Broadcasts a message to all members over TCP including self.- Type Parameters:
M- message type- Parameters:
subject- message subjectmessage- message to sendencoder- function for encoding message to byte[]
-
broadcastIncludeSelf
<M> void broadcastIncludeSelf(String subject, M message, java.util.function.Function<M,byte[]> encoder, boolean reliable)Broadcasts a message to all members including self.- Type Parameters:
M- message type- Parameters:
subject- message subjectmessage- message to sendencoder- function for encoding message to byte[]reliable- whether to perform a reliable (TCP) unicast
-
unicast
Sends a message to the specified member over TCP.- Type Parameters:
M- message type- Parameters:
subject- message subjectmessage- message to sendtoMemberId- destination node identifier- Returns:
- future that is completed when the message is sent
-
unicast
default <M> CompletableFuture<Void> unicast(String subject, M message, MemberId toMemberId, boolean reliable)Sends a message to the specified member.- Type Parameters:
M- message type- Parameters:
subject- message subjectmessage- message to sendtoMemberId- destination node identifierreliable- whether to perform a reliable (TCP) unicast- Returns:
- future that is completed when the message is sent
-
unicast
default <M> CompletableFuture<Void> unicast(String subject, M message, java.util.function.Function<M,byte[]> encoder, MemberId toMemberId)Sends a message to the specified member over TCP.- Type Parameters:
M- message type- Parameters:
subject- message subjectmessage- message to sendencoder- function for encoding message to byte[]toMemberId- destination node identifier- Returns:
- future that is completed when the message is sent
-
unicast
<M> CompletableFuture<Void> unicast(String subject, M message, java.util.function.Function<M,byte[]> encoder, MemberId toMemberId, boolean reliable)Sends a message to the specified member.- Type Parameters:
M- message type- Parameters:
subject- message subjectmessage- message to sendencoder- function for encoding message to byte[]toMemberId- destination node identifierreliable- whether to perform a reliable (TCP) unicast- Returns:
- future that is completed when the message is sent
-
multicast
Multicasts a message to a set of members over TCP.- Type Parameters:
M- message type- Parameters:
subject- message subjectmessage- message to sendmemberIds- recipient node identifiers
-
multicast
Multicasts a message to a set of members.- Type Parameters:
M- message type- Parameters:
subject- message subjectmessage- message to sendmemberIds- recipient node identifiersreliable- whether to perform a reliable (TCP) unicast
-
multicast
default <M> void multicast(String subject, M message, java.util.function.Function<M,byte[]> encoder, Set<MemberId> memberIds)Multicasts a message to a set of members over TCP.- Type Parameters:
M- message type- Parameters:
subject- message subjectmessage- message to sendencoder- function for encoding message to byte[]memberIds- recipient node identifiers
-
multicast
<M> void multicast(String subject, M message, java.util.function.Function<M,byte[]> encoder, Set<MemberId> memberIds, boolean reliable)Multicasts a message to a set of members.- Type Parameters:
M- message type- Parameters:
subject- message subjectmessage- message to sendencoder- function for encoding message to byte[]memberIds- recipient node identifiersreliable- whether to perform a reliable (TCP) unicast
-
send
Sends a message and expects a reply.- Type Parameters:
M- request typeR- reply type- Parameters:
subject- message subjectmessage- message to sendtoMemberId- recipient node identifier- Returns:
- reply future
-
send
default <M, R> CompletableFuture<R> send(String subject, M message, MemberId toMemberId, java.time.Duration timeout)Sends a message and expects a reply.- Type Parameters:
M- request typeR- reply type- Parameters:
subject- message subjectmessage- message to sendtoMemberId- recipient node identifiertimeout- response timeout- Returns:
- reply future
-
send
default <M, R> CompletableFuture<R> send(String subject, M message, java.util.function.Function<M,byte[]> encoder, java.util.function.Function<byte[],R> decoder, MemberId toMemberId)Sends a message and expects a reply.- Type Parameters:
M- request typeR- reply type- Parameters:
subject- message subjectmessage- message to sendencoder- function for encoding request to byte[]decoder- function for decoding response from byte[]toMemberId- recipient node identifier- Returns:
- reply future
-
send
<M, R> CompletableFuture<R> send(String subject, M message, java.util.function.Function<M,byte[]> encoder, java.util.function.Function<byte[],R> decoder, MemberId toMemberId, java.time.Duration timeout)Sends a message and expects a reply.- Type Parameters:
M- request typeR- reply type- Parameters:
subject- message subjectmessage- message to sendencoder- function for encoding request to byte[]decoder- function for decoding response from byte[]toMemberId- recipient node identifiertimeout- response timeout- Returns:
- reply future
-
subscribe
default <M, R> CompletableFuture<Void> subscribe(String subject, java.util.function.Function<M,R> handler, Executor executor)Adds a new subscriber for the specified message subject.- Type Parameters:
M- incoming message typeR- reply message type- Parameters:
subject- message subjecthandler- handler function that processes the incoming message and produces a replyexecutor- executor to run this handler on- Returns:
- future to be completed once the subscription has been propagated
-
subscribe
<M, R> CompletableFuture<Void> subscribe(String subject, java.util.function.Function<byte[],M> decoder, java.util.function.Function<M,R> handler, java.util.function.Function<R,byte[]> encoder, Executor executor)Adds a new subscriber for the specified message subject.- Type Parameters:
M- incoming message typeR- reply message type- Parameters:
subject- message subjectdecoder- decoder for resurrecting incoming messagehandler- handler function that processes the incoming message and produces a replyencoder- encoder for serializing replyexecutor- executor to run this handler on- Returns:
- future to be completed once the subscription has been propagated
-
subscribe
default <M, R> CompletableFuture<Void> subscribe(String subject, java.util.function.Function<M,CompletableFuture<R>> handler)Adds a new subscriber for the specified message subject.- Type Parameters:
M- incoming message typeR- reply message type- Parameters:
subject- message subjecthandler- handler function that processes the incoming message and produces a reply- Returns:
- future to be completed once the subscription has been propagated
-
subscribe
<M, R> CompletableFuture<Void> subscribe(String subject, java.util.function.Function<byte[],M> decoder, java.util.function.Function<M,CompletableFuture<R>> handler, java.util.function.Function<R,byte[]> encoder)Adds a new subscriber for the specified message subject.- Type Parameters:
M- incoming message typeR- reply message type- Parameters:
subject- message subjectdecoder- decoder for resurrecting incoming messagehandler- handler function that processes the incoming message and produces a replyencoder- encoder for serializing reply- Returns:
- future to be completed once the subscription has been propagated
-
subscribe
default <M> CompletableFuture<Void> subscribe(String subject, java.util.function.Consumer<M> handler, Executor executor)Adds a new subscriber for the specified message subject.- Type Parameters:
M- incoming message type- Parameters:
subject- message subjecthandler- handler for handling messageexecutor- executor to run this handler on- Returns:
- future to be completed once the subscription has been propagated
-
subscribe
default <M> CompletableFuture<Void> subscribe(String subject, java.util.function.BiConsumer<MemberId,M> handler, Executor executor)Adds a new subscriber for the specified message subject.- Type Parameters:
M- incoming message type- Parameters:
subject- message subjecthandler- handler for handling messageexecutor- executor to run this handler on- Returns:
- future to be completed once the subscription has been propagated
-
subscribe
<M> CompletableFuture<Void> subscribe(String subject, java.util.function.Function<byte[],M> decoder, java.util.function.Consumer<M> handler, Executor executor)Adds a new subscriber for the specified message subject.- Type Parameters:
M- incoming message type- Parameters:
subject- message subjectdecoder- decoder to resurrecting incoming messagehandler- handler for handling messageexecutor- executor to run this handler on- Returns:
- future to be completed once the subscription has been propagated
-
subscribe
<M> CompletableFuture<Void> subscribe(String subject, java.util.function.Function<byte[],M> decoder, java.util.function.BiConsumer<MemberId,M> handler, Executor executor)Adds a new subscriber for the specified message subject.- Type Parameters:
M- incoming message type- Parameters:
subject- message subjectdecoder- decoder to resurrecting incoming messagehandler- handler for handling messageexecutor- executor to run this handler on- Returns:
- future to be completed once the subscription has been propagated
-
unsubscribe
Removes a subscriber for the specified message subject.- Parameters:
subject- message subject
-