Pregunta

I have a service architecture composed of services that service common areas of the application. Examples of services would be:

  • AccountService (manages client accounts in the system)
  • BillingService (bills clients for products that are configured)
  • UserService (manages user and groups under a given client)
  • NotificationService (sends notifications via email/SMS/push/any method when certain events happen)

I have an ActiveMQ cluster where I push events to act on...which leads to the question...

Where is the right place to put a message listener that reacts to an event for the purposes of sending a notification? A simple example would be: "I want to notify the account owner via e-mail when a new user is added to their account."

Should this listener be in NotificationService (which is intended to be highly generic), or in UserService (where the action is being performed), or in a separate service entirely which acts as a sort of router?

¿Fue útil?

Solución

A router service has two concerns.

It would end up with an infinite number of operations on a ratio of 1:1 with messages within the system and become unwieldy.

The router service must know about every other service.

By adding a listener within each service you limit the listeners only to their responsibility to the service. Following your logic it would make most sense to add the operation to the UserService (which may call the NotificationService to perform the actual work).

Otros consejos

And my opinion is that it belongs to the NotificationService because "I want to notify the account owner via e-mail when a new user is added to their account." It's a notification which happens to be related to an user.

Licenciado bajo: CC-BY-SA con atribución
scroll top