-5

This is quite a general question.

I want to design a set of classes and interfaces so I can swap between messaging systems without changing code, probably between RabbitMq and Kafka.

My main concern is how to abstract the events they handle, as both systems require event handlers but, of course, event handlers on both systems are different.

  • 1
    Possible duplicate of [Choosing the right Design Pattern](https://softwareengineering.stackexchange.com/questions/227868/choosing-the-right-design-pattern) – gnat May 10 '17 at 07:53
  • 1
    my understanding is that these two are fundamentally different. you will have bigger problems than just abstracting the interface – Ewan May 10 '17 at 09:32
  • 1
    Possible duplicate of [How to swap between 2 third-party providers when both implement different events?](https://softwareengineering.stackexchange.com/questions/348670/how-to-swap-between-2-third-party-providers-when-both-implement-different-events) – Zalomon May 10 '17 at 10:36

1 Answers1

0

I would suggest separating business logic module from the communication module.

The business logic module would cover the data processing and would have some interface to the communication logic module.

The communication module would be in charge solely on receiving and sending the messages, without any data processing, apart from basic data validation. The communication module would implement Strategy Pattern, where the business logic module would invoke an exposed interface of the communication module, which, in turn would have two implementations: one using RabbitMq and the other using Kafka.

Assuming your application has the same business logic, regardless of whether you use RabbitMq or Kafka (otherwise you would not be asking this question), you would abstract that business logic, not the event handlers per se.

Let's say that Rabbit Mq has a ShutDown event handler, and Kafka has something called Stop event handler (probably doesn't, but for the sake of the argument). This functionality would be abstracted through the ICommunication interface (for example), using method StopWorking. Then, RabbitMq would implement it using ShutDown, and Kafka would implement it using Stop. Business logic module would see ICommunication.StopWorking. Whatever happens beyond that is of no concern to it and is separated from that part.

Vladimir Stokic
  • 2,943
  • 14
  • 25
  • How would I abstract the event handlers? For instance, RabbitMq has a ShutDown event handler that is specific to RabbitMq. I am not sure about Kafka, but I imagine it will have its own. Should I have a dictionary of delegates that each one has as a field in the communication module? – user197619 May 10 '17 at 07:51
  • @user197619 I expanded my answer with an example based on the comment. – Vladimir Stokic May 10 '17 at 13:00