axon - Is there a way to wait for the results or exceptions of a Saga? -


say have saga money transfer in few milliseconds. have rest controller invokes command triggers saga. how can wait end of saga check results or exception have controller return response? if lone command doesn't trigger saga, use command gateway , callback notify me of success or failure.

update:

i able have controller return response after saga ends by:

1) controller method returns deferredresult save map

2) controller has event handler listens end event, retrieves deferredresult map, , sets result

is there better way go this?

axon designed decouple different components. components handle commands , produce events, other consume events , update query model, or in case of saga, produce commands again.

preferably, user interfaces should designed work in 'eventually consistent' way. when sending command, return value indicates command handled successfully, not side-effects have been executed.

the reason simple when using exaggerated example: if 100 components interested in event produced result of command. want command handler block until these 100 components have been updated? cause dramatic (technical) coupling between these components huge impact on scalability.

given background, still want update ui based on changes in read models. if yo expect side-effect happen time soon, using deferredresult or completablefuture elegant way go about. it's style of query say: 'let me know when ...', opposed 'give me current state'. alternatively, can push updates consumers in real-time. have implemented in several projects based on stomp (with spring websockets).

don't forget clean deferred results map in case have timed out (see deferredresult.ontimeout(). pity if machine crashed because of excessive memory consumption.


Comments