Solace PubSub Integration with MuleSoft

In this blog, we will see how to integrate Solace PubSub + with MuleSoft. Before we get into details, let’s learn a little bit about Solace PubSub platform, its capabilities, how to set it up and finally how to integrate with MuleSoft AnyPoint Platform to amplify its capabilities. So, Let’s begin.

What is Solace PubSub?

Solace messaging APIs provide a smooth access to all Solace PubSub+ capabilities and quality of service levels, and are available for C, .NET, iOS, Java, JavaScript, JMS and Node.js. Solace supports open protocols and open APIs such as Paho and Qpid.

There are two editions Standard and Enterprise. The Standard Edition is a free enterprise-grade substitute to open source with integrated high availability and disaster recovery. PubSub+ Enterprise Edition has additional performance and includes support.

How to Set up Solace PubSub?

There are three options to setup Solace PubSub

  • Using Cloud services like AWS, Azure and GCP

  • Using Docker container

  • Solace Cloud

This document demonstrates integration using option 2 (Using Docker container). Follow some simple steps defined below to setup Solace PubSub

Steps

  1. Download and install Docker on the system https://www.docker.com/products/docker-desktop
  2. Once Docker is up and running, open command prompt and run following command
  3. docker run -d -p 8080:8080 -p 55555:55555 -p:80:8008 -p:1883:1883 -p:8000:8000 -p:5672:5672 -p:9000:9000 -p:2222:2222 --shm-size=2g --env username_admin_globalaccesslevel=admin --env username_admin_password=admin --name=solace solace/solace-pubsub-standard
  4. Now Solace PubSub must be running in Docker container,
  5. Open a web browser and access the Solace PubSub+ Manager using the url: http://localhost:8080.
  6. There should be default Message VPN Service available on main screen. This Message VPN Service is created automatically when the instance is installed on Docker Container
  7. Click on Default Message VPN service to explore more about Solace PubSub+ Manager

How to Integrate Solace PubSub with MuleSoft?

Solace can be integrated using different protocols as mentioned in the beginning of this document, however, this document elaborates integration using JMS and REST. JMS will be used to demonstrate a consumer, while REST will be used demonstrating a publisher.

Follow the steps below to create publisher and consumer service using MuleSoft Anypoint platform

Steps to create a Publisher
  1. Click on the Message VPN option on the sidebar and explore services tab on the right side to view the settings and ports for all protocols.
  1. Now open your MuleSoft Anypoint studio and create a new project; give it any name you like.
  2. Drag a HTTP Listener component to the message flow and configure it as given below.
Protocol HTTP
Host localhost
Port 8081
Path /publish
  1. Drag a Set Payload component and place it right after the HTTP Listener and add the script shown below.
  1. Drag Request component, place it after the Set Payload component and configure it to send request to Solace PubSub using the below details.
Protocol HTTP
Host localhost
Port 9000
Path /try
Method POST
  1. The publisher flow is ready now and should look like the below image
  1. Let’s go back to Solace PubSub web console and select the Try Me option from side bar
  2. Establish connection of publisher and subscriber using topic name try and let other settings as is. You should see the screen like the below image.
  1. Once the connection is established, keep this page open.
  2. Now let’s run the Mule application and open any REST client to publish a message to the topic “try”
  3. Open a REST client(in this case, I am using ARC), enter the URL of the REST API as http://localhost:8081/publish, enter some text data in body section and hit Send button as a POST method. You will get a successful response “200 OK”.
  1. Now go back to Solace PubSub web console where Try Me page was left open and note that message has been received by the Subscriber
Steps to create a Consumer

This document describes creating a consumer using JMS connector in MuleSoft that’s why it is recommended to explore JMS JNDI section from Solace PubSub web console

  1. In same Mule project, drag and drop a JMS listener to the mule flow
  2. Configure JMS listener as shown in the image below

Note: Make sure to click configure button and install sol-jms maven library

  1. Click Test Connection to ensure it is successful and confirm that the configuration is fine.
  2. From the General section in the JMS Listener, enter try for the destination topic and select consumer type as Topic consumer as shown in the image below
  1. In the Mule flow, add a Logger component right after the JMS Listener component and write the payload to the logs to show that message has been consumed.
  2. Now Save the changes and run the Mule application again.
  3. Publish a message from Try Me page in Solace PubSub web console and observe the logs in Anypoint Studio console as shown below.
  1. When messages appear in the Anypoint Studio console, it confirms that your Mule Flow can act as a Subscriber and consume the messages published on the topic “try”.
Checkout the vlog to quickly see all of this in action. Feel free to reach us at [email protected] or visit www.royalcyber.com in case of any questions.

Leave a Reply