This content has been marked as final.
Show 1 reply
-
1. Re: CommandDispatcher message ordering
pferraro Jun 26, 2019 2:14 PM (in response to gbrown1)Commands issued by a single thread are sent in order, but because message reception is not single threaded, ordering on the receiver is not inherently maintained.
You can enforce ordering per sender thread only if the sender waits for an acknowledgement that the command was received before sending the next.
e.g.
public class QueueCommand implements Command<Void, Queue<Object>> { private final Object message; Void execute(Queue<Object> queue) { queue.add(this.message); return null; } } Queue<Object> receivedMessages = new BlockingQueue<>(); try (CommandDispatcher<Queue<Object>> dispatcher = factory.createDispatcher("foo", receivedMessages)) { for (Object message : messages) { dispatcher.executeOnMember(new QueueCommand<>(message), member).toCompletableFuture().join(); } }