In a CQRS/async microservices context, I have a command handler e.g. SendOrderConfirmationEmailCommandHandler implemented in a communications service.
This depends on information from the orders service, which can be retrieved via an GetOrderDetailsQueryHandler.
The sequence of messages for this process is:
SendOrderConfirmationEmailCommand -> GetOrderDetailsQuery -> OrderDetailsRetrievedEvent
Since all messages (including the GetOrderDetailsQuery) are asynchronous by necessity the process executing the SendOrderEmailCommandHandler would exit after dispatching an GetOrderDetailsQuery and then would somehow need to resume where it left off once the OrderDetailsRetrievedEvent is handled.
What sort of pattern can be implemented to deal with bridging the gap between firing off a query and the response message being received such that we are able to retain and link back to the original command message instance for which we have retrieved order details?
Can or should this be handled in the CommandHandler or elsewhere instead?