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?

2 Answers 2


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).

  • This is what I currently have - in your opinion, does this couple UserService and NotificationService too tightly? As compared to NotificationService simply listening to events.
    – Colin M
    Jan 5, 2014 at 16:11
  • No, each has it's own responsibility. The UserService performs / orchestrates the operation to notify the account owner and the NotificationService is the mechanism for doing so. As long as you are reasonably able to swap implementations of the NotificationService without impacting the operation of the UserService they're loosely coupled enough.
    – Kevin
    Jan 6, 2014 at 15:24

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.