284
CHAPTER 6 | Tackle Business Complexity in a Microservice with DDD and CQRS Patterns
var
requestCreateOrder =
new
IdentifiedCommand
bool
>(createOrderCommand,
eventMsg.
RequestId
);
result = await _mediator.
Send
(requestCreateOrder);
However, this case is also slightly more advanced
because we’re also implementing idempotent
commands. The CreateOrderCommand process should be idempotent, so if the same message comes
duplicated through the network, because of any reason, like retries, the same business order will be
processed just once.
This is implemented by wrapping the business command (in this case CreateOrderCommand) and
embedding it into a generic IdentifiedCommand, which is tracked by an ID of every message coming
through the network that has to be idempotent.
In the code below, you can see that the IdentifiedCommand is nothing more than a DTO with and ID
plus the wrapped business command object.
Dostları ilə paylaş: