How to handle commands for aggregates with IDs assigned after command?

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, but then how do I make that quoteId the ID for the aggregate?

How to do this?

Thanks for your help.

Perhaps the ultimate question is:

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.

Hi Jonathan,

we’re doing something similar in our application here. For our UI we allow client-side generated GUIDs and generate a random one on the server side if the client is not capable of generating a GUID.
All of this happens in the controller/business logic before the command is dispatched to the command gateway. The CreateXXXCommand then takes a GUID which is set to the @AggregateIdentifier field in the Aggregate via the Events applied in the Constructor-Command Handler.

For your case it should be possible to retrieve the desired ID from your backend system in the business logic before dispatching the command and (as you stated in your second post) pass it in the CreateQouteCommand to set it in your aggregate.

Hope this helps,
Best Regards,
Jakob

Below is the answer I received on stackoverflow from Steven van Beelen at AxonIQ. Basically, I’ll just get the quoteId from the backend system while executing the command handler that is a constructor for the aggregate.

Hi Jonathan, Jakob,

Ah, nice, happy to see I have already answered your question on Stack Overflow.
And, thank you for sharing the solution with everybody here as well!

Cheers,
Steven