Leveraging Solace Messaging Service In MuleSoft
Messaging Service
Overview:
- Messaging service can be defined as storing data in the form of messages.
- Messaging services are used to make the workflow asynchronous by decoupling different services.
- Messaging services are scalable solutions and it is used to achieve reliability.
- Multiple messaging service providers are available like JMS, Solace, Amazon SQS, Google Pub/Sub, etc.
- Generally, the messaging services have message brokers which will be used to establish the connectivity to different applications and to store/retrieve the data.
- There are two types of messaging available.
Queue:
- In the Queue structure, we store the data in the form of messages.
- The Queue has a 1:1 relationship with the sender and receiver.
- The sender stores the message in Queue and the receiver gets the message from the Queue.
Topic:
- Topics are also known as Pub/Sub model.
- The Topics has a 1:Many relationship with the sender and receiver.
- The Publisher stores the message in Topic and the Topic delivers the messages to all the subscribers.
Let’s discuss Solace Messaging Service.
Solace
Overview:
- Solace is a Message broker primarily used to store the data in the form of messages.
- Solace provides both Pub/Sub and Queue-based messaging.
- Solace is a cloud-based offering which makes it scalable and we use Solace messaging services to achieve reliability.
- We need to configure the Solace message broker to establish the connectivity.
- We need to create a developer account in the Solace platform. Then we can log in to the Solace platform for configurations.

- We need to choose the Cluster Manager to create the service. Hit on create service button and fill in the details to create the service.



Once we hit the create service it will take some time to create the service for us.
Once the service starts we can see the Message Broker service is running in the status page.

We need to get the client credentials from the connect page in order to establish the connectivity. We need to click on the connect tab and choose the Solace messaging to get the necessary details required for connectivity.

We can copy the values of Username, Password, Message VPN, and Secured SMF Host for later use.
Now we need to create the Queue in the message broker for storing the data. To create a queue we can click on the manage tab of the service page. Then we need to click on the Queues.

Once we click on the queue we can click on the “+Queue” button and we need to provide the name for the Queue to create the queue.


We can provide some additional configuration while creating the queue as below.

Once the Queue is created we can see the queue name in the console as below.

We can manage the queue after the queue creation by selecting the queue and clicking on the action.

We can see the queue usage is 0% and no messages are in the queue.
Now we can set up our mule application for the solace messaging service.
Step 1:
- Open the Anypoint Studio create a Mule project and provide a name for the project.

Step 2:
- Now drag and drop two Flows and add an HTTP listener to each flow to create a source listener to get the mule event for the application.

Step 3:
- Now we need to configure the HTTP listener by providing the connector configuration and path.
- In connector configuration, we need to provide the below details.
- Protocol: HTTP or HTTPS
- Host: All Interfaces[0.0.0.0](default)
- Port:8081
- Rest we can leave as default.
- Then hit OK.

- For path we can define any resource path following “/”.(Example: /publish and /consume). Here we are taking two resource paths for different test cases.


Step 4:
- Now we need to add a Solace pubsub module from Exchange.

- Once we get the Solace pubsub module we can see all the connectors to perform the required operation.

- We are using the Publish and Consume component.


- In configure the Consume and Publish components to establish the connectivity and send/get the messages from Solace.
- Connection Configuration:
- Client Username: solace-cloud-client
- Client Password: 3tdn9ujjc04eqamkdc3arsgjed
- Message VPN: muletest
- Broker Host: tcps://mr-connection-465cep1me1q.messaging.solace.cloud:55443

Step 6:
- Then we need to provide the details below to complete the setup for sending and receiving the messages.
Consume:

Publish:

Step 7:
- Now drag and drop a Transform Message shape to transform and write a dummy response as “Message is sent successfully” for the publish flow.

- Drag and drop a Transform Message shape to transform the messages into JSON format to make them more readable.

Step 8:
- Now hit on Save and Run the project.

- In the console, we can see the “Status” as “Deployed” to ensure our app is deployed and ready to be tested.

- Once the Application is up and running we can Test it by triggering the Mule app from Postman.
- Publish Testcase:

- We can see the message count in Solace as 1, as we sent one message to Solace from MuleSoft.

- Consume Testcase:

- We can see the message count in Solace as 0, as we consumed the message in MuleSoft.
