Package io.atomix.cluster.messaging
Interface ClusterCommunicationService
- All Known Subinterfaces:
ManagedClusterCommunicationService
- All Known Implementing Classes:
DefaultClusterCommunicationService
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, Duration)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 TypeMethodDescriptiondefault <M> voidBroadcasts a message to all members.default <M> voidBroadcasts a message to all members.default <M> voidBroadcasts a message to all members.<M> voidBroadcasts a message to all members.<M> voidmulticast(String subject, M message, Function<M, byte[]> encoder, Set<MemberId> memberIds, boolean reliable) Multicasts a message to a set of members.default <M> voidMulticasts a message to a set of members over TCP.default <M,R> CompletableFuture<R> Sends a message and expects a reply.<M,R> CompletableFuture<R> send(String subject, M message, Function<M, byte[]> encoder, Function<byte[], R> decoder, MemberId toMemberId, Duration timeout) Sends a message and expects a reply.default <M> CompletableFuture<Void>subscribe(String subject, BiConsumer<MemberId, M> handler, Executor executor) Adds a new subscriber for the specified message subject.default <M> CompletableFuture<Void>Adds a new subscriber for the specified message subject.<M> CompletableFuture<Void>subscribe(String subject, Function<byte[], M> decoder, BiConsumer<MemberId, M> handler, Executor executor) Adds a new subscriber for the specified message subject.<M> CompletableFuture<Void>Adds a new subscriber for the specified message subject.<M,R> CompletableFuture<Void> subscribe(String subject, Function<byte[], M> decoder, Function<M, CompletableFuture<R>> handler, Function<R, byte[]> encoder) Adds a new subscriber for the specified message subject.<M,R> CompletableFuture<Void> subscribe(String subject, Function<byte[], M> decoder, Function<M, R> handler, Function<R, byte[]> encoder, Executor executor) Adds a new subscriber for the specified message subject.default <M,R> CompletableFuture<Void> subscribe(String subject, Function<M, CompletableFuture<R>> handler) Adds a new subscriber for the specified message subject.default <M,R> CompletableFuture<Void> Adds a new subscriber for the specified message subject.default <M> voidSends a message to a member over TCP.<M> voidSends a message to a 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
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
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
-
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
<M> void multicast(String subject, M message, 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
-
unicast
Sends a message to a member over TCP.- Type Parameters:
M- message type- Parameters:
subject- message subjectmessage- message to sendmemberId- recipient node identifier
-
unicast
<M> void unicast(String subject, M message, Function<M, byte[]> encoder, MemberId memberId, boolean reliable) Sends a message to a member.- Type Parameters:
M- message type- Parameters:
subject- message subjectmessage- message to sendencoder- function for encoding message to byte[]memberId- recipient node identifierreliable- whether to perform a reliable (TCP) unicast
-
send
default <M,R> CompletableFuture<R> send(String subject, M message, MemberId toMemberId, 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
<M,R> CompletableFuture<R> send(String subject, M message, Function<M, byte[]> encoder, Function<byte[], R> decoder, MemberId toMemberId, 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, 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, Function<byte[], M> decoder, Function<M, R> handler, 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, 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, Function<byte[], M> decoder, Function<M, CompletableFuture<R>> handler, 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, 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, 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, Function<byte[], M> decoder, 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, Function<byte[], M> decoder, 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
-