Command Dispatcher

Command Dispatcher delivers commands to their handlers invoking a corresponding handler method for the received command.

A dispatcher can deliver more than one class of commands.

Unlike a Command Handler the dispatcher does not change the state of the business model, neither it produces events.

The dispatcher should be registered within the Command Bus to route the corresponding type of commands.

// Initialize Command Bus.
InMemoryStorageFactory storageFactory = InMemoryStorageFactory.getInstance();
CommandStorage commandStorage = storageFactory.createCommandStorage();
CommandBus commandBus = CommandBus.create(new CommandStore(commandStorage));

// Register an aggregate repository which dispatches commands to aggregates (command handlers).
commandBus.register(new OrderAggregateRepository());

// Post a command to Order aggregates.
DoSmth commandMessage = DoSmth.newBuilder().setSmth(smth).build();
Command command = Commands.create(commandMessage, commandContext);
commandBus.post(command);

results matching ""

    No results matching ""