Reading Time: 7 minutes

Anypoint Templates showcase best practices around most common data integration patterns between two systems, for example, Salesforce and Workday, Salesforce and MS Dynamics CRM, Salesforce and NetSuite, Workday and ServiceNow and so on. With our new series of Pub/Sub templates, implemented using a publish/subscribe architecture, we are providing a more modularized approach to integration by allowing you to decouple source and destination systems and easily incorporate multiple systems without having to modify the existing integration application.

Combining your Anypoint Templates

The Java Messaging System (JMS) API allows applications to use its publish /subscribe approach, where Publisher clients address messages to a topic that serves as a bulletin board. Subscriber clients can dynamically consume these messages by subscribing to that topic. The system takes care of distributing the messages to all present subscribers at the time the message arrives and it ensures that the messages are reliably delivered just once to each subscriber.

JMS Publish-Subscribe Model
latest report
Learn why we are the Leaders in API management and iPaaS

Now let’s take the typical broadcast pattern templates implementation and transform it into this model. If we had two systems in the past, one acting as source and the other one being the destination, we can decouple both parts of the template adding a JMS topic in between, allowing the first one to poll updates from the source and publish them to the topic.

Publishing updates to the JMS topic

The template is now publishing updates obtained from Salesforce into the topic “A” using a canonical form, making it available for currently subscribed consumers to reliably receive them.

We can then redefine the batch job that is responsible for moving the updates into the destination system to consume the mentioned topic.

Batch Job triggered by the Subscriber

This way, we have added a client subscriber to the topic “A”, that consumes the collection of updates (in this case Salesforce accounts) and create/update them into a Database. At the same time, we can add many other subscribers for different systems to the same topic and be confident that the same updates will be delivered to every destination system.

You can download the code for these templates from Anypoint Exchange or open the Exchange from Anypoint Studio and search for “Publish-Subscribe” to import them directly into your Studio workspace.

Breaking Pub/Sub templates into publisher and consumer apps.

With the Pub/Sub templates approach you can easily split the typical Anypoint Templates anatomy into two different applications: a publisher and a consumer. The pattern described above can be implemented within a single application or across multiple applications sharing the same broker. The first approach will give you all the benefits of a decoupled code regarding maintenance and extendibility and the second one will also allow you to dynamically add new destination systems to the integration.

In order to split the template, the endpoints.xml file will then be moved to the Publisher app and the businessLogic.xml file to the Subscriber, each one of them with their own config.xml and errorHandling.xml to maintain the same architecture.

Using external JMS Brokers

For practical reasons, the Pub/Sub templates are implemented using the Mule embedded ActiveMQ Broker, but it can be replaced by other JMS External brokers in order to distribute the applications deployment as needed. You can check more information about the Mule integration with ActiveMQ and how to customize the JMS configuration in this documentation page.

If you are not familiar with connecting to external JMS brokers in Mule, you can check the Sending JSON to a JMS Queue example in Exchange.

We are excited for you to start downloading and customizing our new Anypoint Templates series. We are confident that this will address many requirements around scaling the different patterns we had to a broader variety of use cases, and we would love to hear your feedback.

Thanks for stopping by and please leave your comments!