Hi devs!
In a micro-service infrastructure I'm using RabbitMQ to broadcast messages (translating to events) across the internal network to perform functions. I have a question of possibly conflicting opinion.
Here's an example:
I have 2 services for the purpose of this question, Service A, and Core Service.
Scenario:
Service A completes its task, and needs to "send an email", "update some user statistics", and "Award some points to the user". Those 3 tasks do not belong on Service A, they are things that can be done from a multitude of services. Therefore the code to do these 3 things is on Core Service.
Option 1:
Service A broadcasts 3 Events (one for each action) and sends all 3 in to RabbitMQ. Core Service converts the 3 messages from RabbitMQ back in to 3 Events and 3 Listeners pick them up to perform the 3 actions.
Option 2:
Service A broadcasts ONE event (lets call it "ServiceATaskCompleted"), and sends it on to RabbitMQ. Core Service converts the 1 message (event) from RabbitMQ, and the 3 Listeners pick up "ServiceATaskCompleted", and each listener performs its own action like in Option 1.
Questions:
This really could be a developer preference, but i'm keen to know if maybe there's a "correct" answer here, how would you do it?
Is there any downside to having 3 events instead of 1? Is it a code smell to have an Event be "SendEmail" instead of something more like "onServiceComplete"?
Thanks!
submitted by /u/devsidev
[link] [comments]
from Software Development – methodologies, techniques, and tools. Covering Agile, RUP, Waterfall + more! https://ift.tt/RGicdnm