-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Microservices arhitecture #19
Comments
...these libs are actually beeing used for bigger microservice arcitectures... with tens of hosts, denormalizers, sagas and domains... |
As expected, thanks for your reply. I`ll try to dive more into the documentation to see the bigger picture. |
Can i inject in a saga the viewmodel module? I need to query the data on a specific event to emit specific commands. I`m doing it wrong? The main idea is to implement a transaction involving multiple entities. The only way i achieved this was on host process, on a command observe, but it seems coupled. Thanks |
no problem... for example bootstrap it like that: const pm = require('cqrs-saga')({/**/});
const denormalizer = require('cqrs-eventdenormalizer')({/**/});
// register command handlers
pm.on('command', (cmd) => {
hub.emit('command', cmd);
});
// ...
myhub.on('event', (evt) => {
denormalizer.handle(evt, (errs) => {
if (errs) {
console.error(errs);
}
});
});
// ...
denormalizer.defaultEventExtension((evt, callback) => {
pm.handle(evt, (err) => {
callback(err, evt);
});
});
// ... then you can just require the collection from within the saga handler i.e.: const myCol = require('../viewBuilders/myEntity/collection');
myCol. loadViewModel('id', (err, vm) => {}); |
Thanks a lot. |
One question, in this example, the aggregateId is payload.id, i tried to change it to aggregate.id, in all the files, but the edit and the delete failed, i`m missing something? And the context failed the same. I look on https://github.com/pawarvijay/sample-with-context-and-saga-implemented but no success. |
do you have it on github somewhere? |
yes, here the aggregate id is: aggregateId: 'payload.id'. I read some of your issues on github and you recommand to always send the aggregate id |
Or it is ok to send the payload.id as aggregateId? I |
it should work if you change https://github.com/smariussorin/EventSourcedMicroservices/blob/master/config/saga-config.js#L4 and then adapt this stuff: to something like: var cmd = new Backbone.CQRS.Command({
id:_.uniqueId('msg'),
command: 'deleteAccount',
aggregate: {
id: accountId
},
meta: "smarius.sorin@yahoo.com"
}); PS. it is just your choice how you want to structure the message... ;-) -it doesnt't really matter |
Ok, and if i want to add the aggregateName and context, i need to add them in all the places. Do i need to specifi the context and aggregate name in https://github.com/smariussorin/EventSourcedMicroservices/blob/master/host/public/js/accounts-app.js#L127, or they will be automated fill? Example: Do i need to change the https://github.com/smariussorin/EventSourcedMicroservices/blob/master/domain-account/lib/changeAccount.json to define the structure to include aggregate name and context? |
|
Thanks for your answers and time. |
One minor question about domain: if i need to add created_at field in create events, where is the best way to init this date? i don`t want to send the client date, i want to do it in domain flux. Thanks. |
There s already a feature for this: https://github.com/adrai/node-cqrs-domain#define-the-event-structure If this is not exactly what you want you have to add the the date in each handle for the commands https://github.com/adrai/node-cqrs-domain#command |
Ok thanks, i already use commitStamp, but as i seen is more like a updated_at field. I needed additional field and i didn`t know where is the right place to do this. |
When i`m finished, i will push a example with Angular CQRS. It was hard, but i finally did it. Maybe will help others. |
Very cool! Il giorno 12-giu-2016, alle ore 18:31, Marius Sorin Stratulat <notifications@gh.neting.ccmailto:notifications@github.com> ha scritto: When i`m finished, i will push a example with Angular CQRS. It was hard, but i finally did it. Maybe will help others. You are receiving this because you commented. |
I pushed the Angular CQRS. https://github.com/smariussorin/EventSourcedMicroservices. I manually added the lib of angular CQRS so i can i further modifications. The behavior of getting the collection is disabled, i use my own behavior. Example how to set: I need to add a busy behavior, in 2 weeks most is a full working example |
How does this saga looks like? Il giorno 13-giu-2016, alle ore 22:45, Marius Sorin Stratulat <notifications@gh.neting.ccmailto:notifications@github.com> ha scritto: One minor question: on my saga, when i add a comand to a saga to send, i have the this error, but the command is send succesfully. I tried to add id generator, but it is optional. You are receiving this because you commented. |
I push on https://github.com/smariussorin/EventSourcedMicroservices. Saga-category, on sagas/categoryDeleted. |
And one minor question: viewmodel/eventdenormalizer find method can be used to search in a property of type array? For example: i need to iterate in order.products[x].id. I wanted to avoid getting all the data. |
Try to move saga.commit(callback); 2 lines above for findViewmodels() yes, but it depends on the db implementation i.e. for mongodb it's ok Il giorno 13-giu-2016, alle ore 23:17, Marius Sorin Stratulat <notifications@gh.neting.ccmailto:notifications@github.com> ha scritto: I push on https://github.com/smariussorin/EventSourcedMicroservices. Saga-category, on sagas/categoryDeleted. You are receiving this because you commented. |
for findViewmodels() for mongodb can you give an example? i didn`t find in the example. |
for saga error: saga.commit(callback): to added it next after addCommandToSend? |
findViewModels: this is absolutely ok: https://github.com/smariussorin/EventSourcedMicroservices/blob/master/saga-category/sagas/categoryDeleted.js#L11 saga.commit should be moved between line 25 and 26: https://github.com/smariussorin/EventSourcedMicroservices/blob/master/saga-category/sagas/categoryDeleted.js#L25 |
Thanks. Fixed saga. For the findViewModel i need for https://github.com/smariussorin/EventSourcedMicroservices/blob/master/saga-product/sagas/productDeleted.js. I currently get all data and filter in-memory, and i wanted to get the filter data if possible. |
try
|
like mongodb queries |
Thanks. I`m finished with my project, thanks for all the time and help. |
You're welcome :-) |
Hello, this is a great example of how to use CQRS and Event Sourcing. I was wondering if i use different domains, a single host (the web application) can i achieve a Microservices Architecture? The documentation is good, but i feel it has more power and i want to use them into a Microservice Architecture. Can you give some advice?
The text was updated successfully, but these errors were encountered: