Som Poddar
Som Poddar

Reputation: 1451

Design Pattern for a Wrapper to Message Queue Services

I want to design a wrapper to talk to Message Queue(s)f. The implementation of the wrapper should be generic enough so that client of the library doesn't have to make any code changes if they want to switch from one MQ provider (for example RabbitMQ) to another MQ Service (say Amazon SQS).

What Design Pattern would you recommend for the library and why?

Upvotes: 1

Views: 1848

Answers (1)

ketan vijayvargiya
ketan vijayvargiya

Reputation: 5649

You are looking for the Adapter design pattern.

Let's say you have two queueing technologies: Q1 and Q2. Each of them provides different methods to interact with them. The class design looks like the following:

  • Create an interface, say IQueue, with generic methods. For e.g., getMessage(), postMessage() and deleteMessage().
  • For Q1, create an adapter that is composed of Q1-client and extends IQueue. Similarly, for Q2.
  • Code your application to IQueue. Then, switching from Q1 to Q2 simply involves replacing one adapter class with another.

Upvotes: 4

Related Questions