publish subscribe design pattern
This design pattern can be achieved by using JMS QUEUE. In this exchange pattern publishers send the messages in the Queue. Subscribers get the messages from the queue.
We need three processes to implement this design pattern; a publisher process, a subscriber process and a error handler batch process.
Publisher process.
- Source application invoke this process through web service
- Publisher send the messages of the source application to the queue after successful validation
- Publisher sends the error messages to source application if validation fails.
- Publisher commit the messages to the Queue and send success response to the source application or send failure response if commit to the queue fails.
Subscriber process.
- Subscriber process listen to the Queue.
- Messaging system deliver the messages to the subscriber process
- Subscriber enrich and transform the messages and deliver to the target application
- The messages which could not be posted, are sent to the Error Queue or Error table.(You may use error table, instead of queue to achieve fine grained control)
Batch Process.
- This process handles the failed messages which could not be posted to the target application
- This is a scheduled process which read the messages from the message Queue and try to post the messages to the destination.
- The messages will be written back to the error queue which could not be posted.
- In case if the process support transaction, messages will be there in the error queue, if the messages cannot be posted to the destination.
Use Case
This is asynchronous design pattern variant. You should use this pattern if your integration layer has standard messaging support. It is better to use Queue instead of database to store the messages especially in cluster environment.
Also where there are single publisher and multiple subscriber, you should use this pattern. To handle this scenario with database is not recommended.