so currently I'm implementing a saga with axon framwork, using event sourcing and CQRS.
Circumstances are the following:
I have 3 Microservices, m1, m2 and m3
A user enters data for 3 entities e1, e2 ,e3 in a GUI that are handled and persisted by m1,m2,m3 respectively, so m1->e1,m2->e2,m3->e3
Now to the necessity of the saga:
e1 can't exist without e2 and e2 cant exist without e3.
So all 3 entities will have to be successfully created by their respective services and if one fails, the saga needs to perform compensating transactions to ensure consistency. First m1 creates e1, emits an e1CreatedEvent and an orchestrator sends a createE2Command as a reaction to that etc.
Now my problems:
How do I get/store the information that the user enters? In a single RequestBody? Then what do I do with that data? Because it needs to be cached somehow in order to be sent with the commands.
For example m1 creates a createE1Command and adds the information from e1 to it, then after it is successfully created the orchestrator will initiate a createE2Command and THEN add the info for e2 to that command before sending it....for that to happen, the info for e2 needs to be stored somehow until it is needed.
Sample Code:
@Saga
public class ManagementSaga{
@Autowired
private transient CommandGateway commandGateway
@StartSaga
@SagaEventhandler
public void handle (e1CreatedEvent e1CreatedEvent){
commandGateway.send (new CreateE2Command (e1CreatedEvent.Id, **HERE NEEDS TO BE THE INFO THAT THE USER CREATED PREVIOUSLY**)}}
Do I just create an object that holds the information for these three entities? That feels really wrong.
Now I understand that maybe it is really bad to choose such a domain model and one should probably avoid it if possible, but it's for sceience :-)