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
Solace PubSub+ Cloud Sign In/Sign Up Page

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.
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.
Welcome Page
To Create Service: 1. Select Service Type

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.”
To Create Service: 1. Select Service Type

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.
2. Select Cloud
2. Select Cloud

Choose a region. I selected “US East (North Virginia)”.
3. Select Region

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.
4. Service Details

Next, choose the Message VPN name and click “Start Service” to launch the service.

Your Service should be running now.
Services Running

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.
Connect Using a Supported Client Library

After choosing a protocol, you’ll see all of the Connection Details used in MuleSoft (JMS Config) to connect to Solace.
Solace Messaging: Get Started

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 New KeyStore Type

Select the “Import Trusted Certificate” option (command+T or Ctrl+T) to import the PEM certificate.
Import Trusted Certificate

Give it a name and choose the Solace PEM certificate that was downloaded before importing it.
KeyStore Explorer Window

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.
Saving KeyStore

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.
Package Explorer

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.
Manage Settings

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.
Saving KeyStore

When you select the “Services” tab, you will see a list of all the Services that are enabled.
Services

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.
Settings

You may view statistics such as the number of messages sent and received in your messaging VPN under “Stats.”
Stats

Client Connections

Due to the pre-filled nature of these settings, there is no need to explicitly set the client connections.
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.”
Client Authentication Settings

Access Control – Client Usernames
Select/Add 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.
Select/Add 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.
Select/Add Subscriptions: 1. Queue a.

Select/Add Subscriptions: 2. Queue b.

Select/Add Subscriptions: 3. Queue c.

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.
Adding the Solace and JMS modules

The JMS connectors will be accessible in the Mule Palette after these modules are added:
Mule Palette

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:Adding the Solace and JMS modules Adding the Solace and JMS modules

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:
Publishing Message to Solace Topic

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.
Testing the path

I used the following JSON Body for this demonstration:
JSON body for testing the path

The message published to the Topic can be seen in the Solace Queue mapped to it, as shown in the screenshot below.
Published message view in the Solace Queue

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.
Queue flow

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.
Adding a message

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.
Selecting Acknowledge Mode

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:
Mule Debugger

Then, the message is converted into the required format.
Converting message in 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.
Salesforce Accounts

The message in the Queue has now been removed:
Final outcome

Thank you for taking the time to read the article. I hope you find it useful.

About the Author

Preena Patel
Preena is a Technical Writer at Maropost. She is an experienced Technical Writing professional who has been working with clients and enterprises in the information technology and services industry including Microsoft. She is skilled in WordPress, Technical Documentation, Markdown, Confluence, Jira, Visual Studio Code, Communication, Editing, and Academic Writing. She holds a Bachelor of Technology – B. Tech. focused in Information Technology from Symbiosis International University and has achieved certification from Udemy for Tech Writers Master Class.
Preena enjoys blogging about tech, reading autobiographies, poetry and books that help with self-improvement, writing poetry, watching documentaries and playing football. With a passion for finding the mysteries of the universe and truth of the nature, she practices Vipassana Meditation and volunteering work that helps others and her grow into a better person.
Solace Scholar
Solace Scholars

The Solace Scholars Program encourages writers from our community to create technical and original content that describes what our technology and/or third-party integrations are being used for and exciting projects that are made possible by event-driven architecture. Solace Scholars are great at solving challenges and explaining complex ideas. If you're interested in writing for us and learning about what you can earn, check out the website and submit an idea to us!