Reputation: 17451
I know the subject line doesn't make sense given the way Axon works, but here is my problem:
I need to create a new instance of aggregate, "Quote", that is tied to a backend system of record. That is, the aggregate ID must eventually match the ID assigned in the backend system.
So, my uiServer app is calling commandGateway and sending it a CreateQuoteCmd, but I don't know what to pass as the target aggregate ID, since the ID will come from a backend system called by the command handler. The uiServer cannot assign the quoteId. The command handler for CreateQuoteCmd contacts our backend system to get the new quoteId. The backend system also supplies several default values which will be placed in the aggregate.
So, how do I make that quoteId the ID for the aggregate?
What do I pass as the target aggregate ID in the command object?
Is it true that I must pass a target aggregate ID in CreateQuoteCmd instead of allowing the object to set its own ID in the command handler after communication with the backend system? Thanks for your help.
Upvotes: 1
Views: 534
Reputation: 7275
The Command which will create an Aggregate is not inclined to have a @TargetAggregateIdentifier
annotated field. This holds as the field which is the 'target aggregate identifier', cannot point to an existing aggregate, as that command will be the starting point of an aggregate.
The creation of the Aggregate Identifier can happen at several points in your system, and is really up to you.
The important part here though is that the @CommandHandler
annotated constructor within an Aggregate has a return value, which is the Aggregate Identifier you have assigned to that Aggregate.
You should thus handle the result given to you from the CommandGateway
/CommandBus
when dispatching your CreateQuoteCmd
. This should contain the QuoteId
you have assigned to your (I assume) Quote
Aggregate.
Upvotes: 2
Reputation: 2405
You need to get the aggregate ID from the external system before sending the command (at domain or application service layer)
Upvotes: 0