Skip to content

Commands

Marek Fišera edited this page Feb 21, 2016 · 3 revisions

In comparison to the Events, Commands represent a request for a change in application state. Before raising command, parameters should validated so the command most likely succeeds.

The command is as POCO-style class that contains parameters required for change the state. Every command type must have exactly one handler responsible for executing the business logic. As in Events commands are post through ICommandDispatcher facade and handled by registered ICommandHandler.

A command be definition doesn't have direct output, as it is not guaranteed to be executed immediately. A user (or a command sender) is notified by a raised event from a command handler). Caller only has guaranteed that command is saved and at some time it will be executed.

Paralel command execution

In terms of the CQRS a dispatcher should handle the paralelity of command handling. This can be solved at three levels:

  1. In basic implementation, all required for a change in an application should be executed in serial manner. This guarantees the ACID behavior.

  2. When your application needs more throughput, you can design which command types can execute in paralel. Simply "making an order" and "publishing a text description on a product" shouldn't interfere.

  3. You can design which command of same type, but with different key parameters, can execute in paralel. An "order for product A and B and other order for products C and D" can be executed in paralel, because the capacity of both are separated. But when one product is in two orders, these shouldn't be executed paralely. These rules can be more complicated, but the principle remains.

Scalability

When commands are designed to execute in paralel, you can even scale their execution across servers. Typical scenario is that you have one dispatching server, where all commands arrive. A command handlers registered here are typically only "HTTP wrappers" that redirect commands to appropriate servers using HTTP protocol.

Extensions

In addition to the dispatching command over HTTP we have also implemented Behaviors support for interception on command handlers.

You can’t perform that action at this time.