Comments (6)
Hi @bkak!
Good input! At the moment I have not so much time to read your links completely, but I think this is really an open task... When I implemented the sagas in the cqrs-domain I decided to just implement a simple version first... and perhaps now it's time to implement a better version for sagas... ;-)
The momentary solution in cqrs-domain is to save some data in the saga and handle these compensation actions manually... (you can save some data by calling this.set()) like here: https://github.com/adrai/cqrs-sample/blob/master/domain/sagas/itemSaga.js
If you want and have more time you are free to propose something via pull request... :-) (I know the code is not really documented, but why not trying...?)
from node-cqrs-domain.
Ok gr8.
I shall give it a try. I am very new to Node, its just a month that I am playing with it.
With your help I should be able to create clemens saga handlers.
Shall buzz u once I get a prototype done.
Thanks a lot.
from node-cqrs-domain.
Hi,
The problem that I am facing in using this is I need Saga capability to issue commands to different AR of another BC in the same internal system, but Business Exception may arise in another BC. If there is any Exception I need to rollback/compensate the commands that were issued in this session.
Writing compensation for each and every command will be little difficult. In my domain if there is any Business Exception I can tell the user, that action has failed due to this "Business reason". User can make appropriate changes and issue it again.
Initially I thought to implement RoutingSlip that Clemens Vasters is talking about. Here writing compensation for every command will be tedious.
I feel this problem can be solved with Unit of work. If I encapsulate all the commands raised by the User or by the saga in the same session, and if all of them are successful then only on commit push the events to event store and publish all the events generated by them. This way no rollback/compensate will be required.
Can you think of any other solution to this problem?
Your feedback is highly valuable for me.
Thanks,
Bhoomi
from node-cqrs-domain.
Hi Bhoomi!
This smells a little like transactions, and this is not CQRS-like...
There is no session... and a saga can't react on commands, only on events.
If you want to react on commands use commandHandlers...
There you can do things like:
var commandHandlerBase = require('cqrs-domain').commandHandlerBase;
module.exports = commandHandlerBase.extend({
commands: [
'archive',
'unarchive',
'deleteArchive'
],
aggregate: 'archive',
unarchive: function(id, cmd) {
var self = this;
this.loadAggregate(id, function(err, aggregate, stream) {
var myObject = aggregate.get('myObject');
if (myObject) {
(new self.Command({
command: 'addMyObjectToOrganisation',
payload: {
id: aggregate.get('organisation'),
myObject: myObject
},
head: cmd.head
})).emit(function(evt) {
if (evt.event !== 'commandRejected') {
self.finish(id, cmd);
(new self.Command({
id: cmd.id,
command: 'deleteArchive',
payload: cmd.payload,
head: cmd.head
})).emit();
} else {
self.finish(id, cmd, evt.payload.reason);
}
});
}
});
}
});
from node-cqrs-domain.
Oh no no I am not trying ask Saga to react to Commands.
Ok, my goal is to have Transactional Saga.
I shall give an example :
User places a Sales Order. CreateSalesOrder is the command to be fired on SalesOrder AR.
It raises an event SalesOrderCreated. This event is subscribed by Saga and it raises command PostAccountEffect on Accounting AR. Something goes wrong and Accounting AR raises Business Exception.
I want all the events to be rolled back instead of doing compensation.
Therefore I thought if I can encapsulate this in one UOW, and commit the UOW when all the commands are executed. On UOW Commit save all the events together in EventStore and then publish it. In case of any Business Exception do not commit the UOW but send Business Exception in response.
from node-cqrs-domain.
Ok, feel free to try it... At least you learned something... :-)
PS. events are published by the eventstore... (so they will be already committed)
from node-cqrs-domain.
Related Issues (20)
- Let MongoDB generate the aggregate ID? HOT 6
- Is it possible to replace the t4-validation? HOT 5
- CQRS Question about bulk import HOT 5
- revision guard HOT 6
- [Bug] Precondition aggregate is empty HOT 2
- How to use in AWS Lambda HOT 5
- Can a command fire more than one event? HOT 3
- Access meta in command HOT 2
- How to use domainPath in unit tests HOT 7
- Context and aggregateId HOT 5
- defaultCommandHandler bug, adding "undefined" to array of evtsToDispatch HOT 1
- How to clear/init HOT 2
- Same event name in different contexts HOT 2
- default value command schema HOT 2
- Where to catch Error: Please pass a valid aggregate id! HOT 11
- Transaction with two aggregates HOT 1
- How to handle errors thrown from defineCommand / defineEvent handlers? HOT 9
- Unique field validation HOT 7
- rollback aggregate to a given revision HOT 5
- Update deps HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-cqrs-domain.