thenativeweb / node-cqrs-saga

Node-cqrs-saga is a node.js module that helps to implement the sagas in cqrs. It can be very useful as domain component if you work with (d)ddd, cqrs, eventdenormalizer, host, etc.
http://cqrs.js.org/pages/saga.html
MIT License
61 stars 16 forks source link

handling domain failures in saga #31

Closed pawarvijay closed 8 years ago

pawarvijay commented 8 years ago
adrai commented 8 years ago

something like this:

module.exports = require('cqrs-saga').defineSaga({// event to match..
  name: 'commandRejected', // optional, default is file name without extension
  aggregate: 'payment',
  context: 'sale',
  version: 2, // default is 0
  containingProperties: ['payload.transactionId'],
  id: 'payload.transactionId',
  existing: true // if true it will check if there is already a saga in the db and only if there is something it will continue...
  // payload: 'payload' // if not defined it will pass the whole event...
  // priority: 1 // optional, default Infinity, all sagas will be sorted by this value
}, function (evt, saga, callback) {

  var cmd = {
    // id: 'my own command id', // if you don't pass an id it will generate one, when emitting the command...
    name: 'cancelOrder',
    aggregate: {
      name: 'order',
      id: saga.get('orderId')
    },
    context: {
      name: 'sale'
    },
    payload: {
      transactionId: saga.id
    },
    meta: evt.meta // to transport userId...   if not defined in cmd, it will defaultly use it from event
  };

  saga.addCommandToSend(cmd);

  saga.commit(callback);
}).defineShouldHandle(function (evt, saga) {
  return evt.payload.command.name === 'pay';
});
pawarvijay commented 8 years ago

Thanks @adrai this will do :+1:

Does this also means that for every aggregate wherever i want to handle "commandRejected" event i need to create this kind of saga (with aggregate & context defined if any) FOR THAT AGGREGATE ?

adrai commented 8 years ago

Yes

Il giorno 25-feb-2016, alle ore 07:34, vijay pawar notifications@github.com<mailto:notifications@github.com> ha scritto:

Thanks @adraihttps://github.com/adrai this will do [:+1:]

Does this also means that for every aggregate wherever i want to handle "commandRejected" event i need to create this kind of saga (with aggregate & context defined if any) FOR THAT AGGREGATE ?

Reply to this email directly or view it on GitHubhttps://github.com/adrai/node-cqrs-saga/issues/31#issuecomment-188636028.