This week, we’ll study a pattern known as Publish-Subscribe Channel.
When do I use this pattern?
A Publish-Subscribe Channel is used when the sender wants to send messages to multiple receivers. For example, invoice data can be sent to a collection centre and a reporting software. In this blog, I’ll reuse the example from Durable Subscriber blog.
Publish-Subscribe Channel in CPI
Integration Flow – Publish Invoices
The Topic Name will be ‘Invoices’.
This integration flow publishes the invoice data on ‘Invoices’ topic.
Integration Flow – Collection Center
This integration flow is step 13 from Jonathan Fung‘s blog on the Publish-Subscribe pattern. The difference is that we are logging the payload instead of sending it to SFTP. Also, the Queue Name will be ‘CollectionCenter’.
Integration Flow – Financial Reporting
Similarly, this integration flow is step 13 from Jonathan Fung‘s blog on the Publish-Subscribe pattern. The difference is that we are logging the payload instead of sending it to SFTP. Here, the Queue Name will be ‘FinancialReporting’.
Integration Flows Collection Center and Financial Reporting subscribe to get the messages from Invoices topic.
To demonstrate the Publish-Subscribe pattern, we’ll deploy Publish Invoices integration flow. We can see 1 message in each queue.
Now, we’ll deploy the Collection Center integration flow. The number of messages in CollectionCenter queue reduces to 0.
At this time, the financial reporting system is down. The Enterprise Messaging will keep the message in Financial Reporting queue until the message expires.
Once the financial reporting system comes back up, we can see that it consumes the message.
As you can see, a Publish-Subscribe channel ensures that each subscriber gets the message once.
While this pattern allows adding the subscribers on the fly, a new subscriber may not get the messages that are already published, it will only get newly published messages.
EIPinCPI Rating – 10/10
Enterprise Messaging supports publish-subscribe channels out of the box. Therefore, this pattern gets 10/10 EIPinCPI rating.
Publish-Subscribe channel is used when a sender wants to send messages to multiple receivers.
- Publish-Subscribe Channel Pattern in Enterprise Integration Patterns
- Jonathan Fung‘s blog on the Publish-Subscribe pattern
- CPI Components
Hope this helps,