4

I'm guessing, it is a common question, but I will try to describe my current issue.

I have a base service, lets name it 'CoreService', that provides I would say "main" functionality: handle data in DB (we have a centralized DB in our applications). There are a number of other applications, some of them have their own DB for local purposes. And there is one simple 'NotificationService'. Its purpose is to broadcast messages to different subscribers.

Usually, this NotificationService is called from 'ExternalWorld' and sends notifications to different services (among them is 'CoreService').

Today I saw a necessity to call 'NotificationService' from 'CoreService'.

My concern here is that I am introducing a circular dependency: NotificationService needs to know how to send messages to each service (including 'CoreService' so it needs to know about the 'CoreService' interface and as a result it needs to reference 'CoreService') and 'CoreService' needs to send messages to 'NotificationService (so it needs to reference it too)... Circular dependency...

Question: How should we build our architecture to handle such issue?

Thanks a lot!

1
  • NotificationService is a mediator here, isn't it?
    – Budda
    Jan 24, 2011 at 22:28

2 Answers 2

4

You have to switch from point-to-point to a mediator. Mediator will now take the responsibility of binding the source to destinations and route/publish the messages appropriately (ESB rings in my head).

Explanation

You doesn't directly reference CoreService from NotificationService or vice-versa. Both will subscribe to a topic of their interest. For e.g CoreService publishes events to a topic that NotificationService will subsribe to (and CoreService will also subscribe to a topic that NotificationService publishes events to). It is then the responsibility of the Topic handler (messaging system or ESB etc) to forward the events to all the subscribers of a given topic. This way the services are loosely coupled from each other and needn't even know of their existence.

Currently, you are using NotificationService as a mediator/ESB thus making it as a infrastructure service if you will and hence the issues like circular dependencies etc. It is no longer a business service.

2
  • Agree. Doesn't it obvious that my 'NotificationService' is planned to be a mediator? Probably I missed something? What traits 'NotificationService' should have to be a mediator? Thanks
    – Budda
    Jan 24, 2011 at 22:45
  • My intention was to use 'NotificationService' as 'Topic handler'. Could you please see here (stackoverflow.com/questions/4798319/service-as-mediator-in-soa) if I correctly understood your suggestion?
    – Budda
    Jan 25, 2011 at 20:25
0

When I completed writing question I found some idea:

Inside of 'NotificationService' I need to define 2 interfaces 'IMessagesSender' and 'IMessagesReceiver'.

  1. Every subscriber should implement 'IMessagesReceiver' and it's address should be written into configuration file of 'NotificationService';
  2. Every message sender should consume 'wsdl' file that describes 'IMessageSender' interface and should have record in own configuration file with 'address' of the NotificationService.

In this case we won't remove circular dependency, but it seems like a solution...

Right now, it is hard for me to say what is the best way ans what are pros and cons of this solution, so please comment it (and/or suggest the better one).

Thanks a lot!

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.