Preena Patel is a technical writer at Maropost.
In this article, I’ll show you how to use Solace PubSub+ with MuleSoft to publish and consume messages.
What is PubSub+?
PubSub+ is a platform for designing, discovering, streaming and managing events across distributed enterprises. It includes all of the tools required to run a modern event-driven architecture (EDA). The platform’s main components are PubSub+ Event Broker, PubSub+ Event Portal, and PubSub+ Cloud Console. Visit the PubSub+ for Developers website for more details.
Event-driven architecture offers benefits such as adaptability, extensibility, agility, user friendliness, real-time interactions and on-demand processing. Although it is crucial to see that design is thorough and design and tracking are given more thought.
Let us now look at the steps involved in integrating Solace and MuleSoft.
1. Registering for a Solace Cloud Trial Account
You can sign up for a Free Solace trial account by clicking on the following link: https://console.solace.cloud/login
To register, click “Sign Up” and complete the fields. In your inbox, you will find a welcome email. You can now sign in using your credentials on the login page.
2. Establishing the Messaging Service
When you log in with your credentials, you will see a welcome screen similar to the one below.
To create a Service, click on “Cluster Manager” on the left side of the screen.
The following services are supported by Solace PubSub+ event brokers, according to the official Solace documentation for Managing Services – Solace PubSub+ event brokers:
- Solace Message Format (SMF) — On the Message Backbone interface, this Service allows clients to communicate with an event broker.
- Solace Element Management Protocol (SEMP) — On the Management interface, this Service allows management applications to communicate with an event broker.
- Web transport—This Service allows Web clients to communicate with an event broker.
- Solace Representational State Transfer (REST) Service — This Service enables REST clients to communicate with an event broker via standard HTTP requests.
- Message Queuing Telemetry Transport (MQTT) — Using the MQTT messaging protocol, clients can communicate with an event broker.
- Advanced Message Queuing Protocol (AMQP) — Using the AMQP open standard application layer protocol, this Service allows AMQP clients to communicate with an event broker.
Let us start a Service.
First, choose the Service Type that you want to use. Services are classified into two types:
- Enterprise: A highly available service on dedicated infrastructure with connections that can be customised.
- Developer: A dedicated infrastructure service with 100 connections.
In this case, I’ve chosen “Developer.”
Select the Cloud after that. For my situation, I opted for “Amazon Web Services,” or simply “AWS.” As shown in the following screenshot, there are various clouds from which to choose. Choose any cloud based on your requirements.
Choose a region. I selected “US East (North Virginia)”.
Assign a name to the Service. Create it using the name of the Cloud and the Environment, such as sol-aws-dev
, as an acceptable naming standard. If your team has any guidelines for naming the messaging services, you can ask them.
Next, choose the Message VPN name and click “Start Service” to launch the service.
Your Service should be running now.
3. MuleSoft Configuration of the Solace KeyStore
To connect to the Messaging Service after we have created it, we must configure the MuleSoft KeyStore.
To access the settings for the Services, click the Messaging Service.
Once entered, go to the top of the screen and click on the “Connect” option, then choose the protocol you want to use to connect to the Service. We employ the “Solace Messaging” option in our POC.
After choosing a protocol, you’ll see all of the Connection Details used in MuleSoft (JMS Config) to connect to Solace.
You can download the TrustStore certificate by clicking on the “Download PEM” link, as shown in the screenshot above.
You need to change the PEM file’s format to JKS. We’ll use the KeyStore Explorer tool to convert this file (you can get it here: KeyStore Explorer – Download). As shown in the screenshot, open KeyStore Explorer and create a new JKS KeyStore Type.
Select the “Import Trusted Certificate” option (command+T or Ctrl+T) to import the PEM certificate.
Give it a name and choose the Solace PEM certificate that was downloaded before importing it.
Select “File” then click on “Save As.”
Enter a password, then type it in again. The password you supplied must be remembered since you must use it in the MuleSoft Configuration (JMS Config). To save the converted JKS file to your machine, you will see a screen similar to the one below.
Just import this JKS file into your Mule Project at this point. You can use it as long as it’s in the same location as mine, which is src/main/resources/keystores.
4. Configuring the Messaging Service
To link the clients to the event broker, we must configure the Messaging Service according to our requirements.
Click on the “Manage” tab at the top of the screen, or adjacent to the “Connect” tab.
Spot and click on the “Message VPN” button in the middle, under the PubSub+ Broker Manager Quick Settings label. A new window will be launched.
When you select the “Services” tab, you will see a list of all the Services that are enabled.
You can see every Service that is active by selecting the “Services” tab.
The settings I developed for the Proof of Concept are listed below. If you’re experimenting, you can configure your own preferences or use mine as a basis.
By selecting “Show Advanced Settings,” as shown in the screenshot below, you can also change the message VPN settings.
You may view statistics such as the number of messages sent and received in your messaging VPN under “Stats.”
Client Connections
Due to the pre-filled nature of these settings, there is no need to explicitly set the client connections.
Access Control – Client Authentication
Details about the authentication method you want to use are available on this tab. “Basic Authentication” is enabled by default. You could enable “Client Certificate Authentication” if you want to use it. I’m employing “Basic Authentication” in my situation. The following screenshots show the settings for “Client Profiles,” “ACL Profiles,” and “Client Usernames.”
Access Control – Client Usernames
5. Setting up Queues
Event broker endpoints in Solace PubSub+ are used to store guaranteed messages. Queues and topic endpoints are two different sorts of endpoints. By using topic endpoints, JMS (that is, durable topic subscriptions).
By selecting the “Add Queue” button as seen in the screenshot, I created the following three queues.
Distinctions between Queues and Topics
Queues:
- Permit one-on-one communication (Point-to-Point).
- Typically used when sending a single event to only one consumer.
Topics:
- Permit one-to-many communication (Publish-Subscribe).
- When you want to send a single event to multiple consumers, this is the method to use.
As shown in the screenshots below, I created a Topic Subscription for each Queue.
6. Setting up the MuleSoft Project
The following dependencies must be added to the MuleSoft project’s pom.xml file. Three options exist for doing this. The modules can be added directly into the pom file, using Exchange from the Mule Palette, or by selecting Manage Dependencies > Manage (or Add) Modules from the context menu when you right-click on the project.
The Solace and JMS modules must be added before we can construct our Mule application.
The JMS connectors will be accessible in the Mule Palette after these modules are added:
After obtaining these, you should create a Global Element for the JMS Configuration and fill it with your desired settings and the connection details from Solace. Here’s what that looks like:
Note: This GitHub repository contains all of this code. If you have any doubts, you can double-check the settings and properties there.
7. Publishing Message to Solace Topic
In my Mule flow, I added an HTTP Listener to be able to listen for a request containing the content that I want to publish to the Solace Topic. You can see how I configured the JMS Publish connector here:
8. Putting the “Happy Path” to the Test
To verify that everything was configured correctly, launch the Mule App locally.
Send a POST request from Postman after the app has started to run (you can also use the Advanced REST Client, cURL, or any other tool to send a request to your local app).
The payload you send here will be read by the Mule app and published to the Solace Topic.
I used the following JSON Body for this demonstration:
The message published to the Topic can be seen in the Solace Queue mapped to it, as shown in the screenshot below.
9. Adding a Message to the Solace Queue
Messages that have been queued must now be processed. In my case, the queued message contains information from a Salesforce Account. In SFDC, I need to subscribe to this queue in a flow, transform it, and create an Account object. I’ve created a new flow called solace-jms-subscribe
to accomplish this.
Please note that the “Acknowledgement Mode” is set to “Manual” in the “On New Message” component settings because we want to delete the message from the queue only after further processing and sending the positive Acknowledgement.
As demonstrated, there are various acknowledgement modes.
You may read more about each parameter in the https://docs.mulesoft.com/jms-connector/1.7/jms-ack file.
As you can see in the following screenshot when the project is deployed in Anypoint Studio, the “On New Message” JMS Subscriber automatically consumes this message:
Then, the message is converted into the required format.
Using the “Create” Connection, the account is successfully created in Salesforce. The “Positive Ack” JMS connector then returns a positive acknowledgement to Solace.
The message in the Queue has now been removed:
Thank you for taking the time to read the article. I hope you find it useful.
About the Author
Explore other posts from categories: For Developers | Products & Technology | Solace Scholars