php - message queue - smallest amount of work for a consumer -
this question architecture / design:
i have consumer needs perform x numbers of tasks, when should think breaking consumer smaller task and/or adding smaller tasks own consumer?
example:
consumer foobarshipping does
- adds database entry reporting
- adds database entry account
- adds database entry shipping
- generates shipping invoice ( pdf or other formats if needed )
- creates notification shipping
- creates notification account
so question is, when break out bullet points smaller consumers? consumer runs fine feel it's getting large , needs refactored smaller, more manageable processes.
should each bullet point it's own consumer? can see breaking them 3 consumers
- database
- pdf ( documents )
- notifications
but smallest unit of work consumer should do? need consumer run sql statement?
i watched
and me consumer looks basic tasks kick off other basic tasks.
for general architecture, has 6 modules , each want grouped into:
- 1 adds database entry reporting
- 1 adds database entry account
- 1 adds database entry shipping
- 2 generates shipping invoice ( pdf or other formats if needed )
- 3 creates notification shipping
- 3 creates notification account
if implementing repository pattern, group 1 should separated 3 repositories. each repository handle each entity (reporting, account, shipping); can provide insert, update, delete , select operation.
same group 3, don't think general notification object (class in term) thing because can grow x, y, z entity notification.
but don't worry, @ right path. if talk dependency, constructor injection, separate 3 objects. general idea foobarshipping ship method:
foobarshipping.ship(invoice inv){ invoicerepository.insertnew(inv); invoicegenerator.generateinvoice(inv); invoicenotification.notify(inv); }
and general idea invoicerepository.insertnew:
invoicerepository.insertnew(invoice inv){ reportingrepository.insertnew(inv.reporting); accountrepository.insertnew(inv.account); shippingrepository.insertnew(inv.shipping); }
same idea invoicenotification.notify:
invoicenotification.notify(invoice inv){ shippingnotification.notify(inv); accoountnotification.notify(inv); }
it may need adjustment regarding data structure , implementation though. general idea. can refer article (refactoring aggregate services) references though.
Comments
Post a Comment