Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
270 views
in Technique[技术] by (71.8m points)

abort - Preventing action in CQRS

I'm pretty new to CQRS and I have run into a question that I don't see a great way to solve in an event-driven architecture. Hope anyone can help me out with this!

The setup

Lets say I have broken down the system into smaller subsystems (domains) which are all separated in microservices over multiple physical machines.

Lets say we have a CRM system with the following entities: Customer, SalesPerson and Discussion.

For the sake of this example, each entity is part of a separate domain.

Discussions know about sales and customers. Sales know about customers. Customers doesn't know about any external domain / system.

In our UI we have an action which is "delete customer X".

The question

What we are trying to achieve is to inform the user about which effects the action might have (i.e. also deletes the related discussions) and give that user the opportunity to abort the action.

Is there a standard way to handle these scenarios?

One concern that I have is that the normal flow of actions is cascading asynchronously. But the abort-scenario is synchronous in that we cannot proceed before we get an answer from external systems about the calculated effects.

In some way I feel that this scenario isn't really covered by the CQRS event pipe but rather a separate solution.

Kind regards Richard

question from:https://stackoverflow.com/questions/65927724/preventing-action-in-cqrs

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It sounds like deletion wants to be a saga; it might even be worth having deletion be its own service.

In this scenario, you would have a ProposeDeletion command which starts a deletion saga. The saga has the effect of querying discussions (etc.) to find out what would be deleted (if consistency is required, proposal might also stop new discussions involving the customer from being created: this would be sending a command to effect that change in the discussion service), notifying affected sales people, etc.

The saga is queryable, and its state can be derived from responses to queries it's initiated etc. Once the proposal effects have completed, the saga is then waiting for a ConfirmDeletion command to effectuate the deletion.

Obviously some deletions will be proposed and not completed. For this case, you'll need to have proposed deletions which haven't completed within a certain amount of time get an AbandonDeletion command which prevents a proposed deletion from being confirmed and effectively undoes any effects it performed after proposal (e.g. reenable new discussion creation for a customer).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...