Connect with Solace from MuleSoft

 

To show how we connect with Solace from MuleSoft we will create a Mule project and import a Solace jar to connect with the Solace environment

Let`s create a Solace project in MuleSoft

 

Now we have to import the Solace jar using Maven, Open pom.xml

Add properties

<solace.version>10.3.1</solace.version>
<javax-jms-version>1.1</javax-jms-version>
<javax.jms.api.version>2.0.1</javax.jms.api.version>

Add shared libraires

    <sharedLibrary>
        <groupId>com.solacesystems</groupId>
        <artifactId>sol-jms</artifactId>
    </sharedLibrary>
    <sharedLibrary>
        <groupId>com.solacesystems</groupId>
        <artifactId>sol-common</artifactId>
    </sharedLibrary>
    <sharedLibrary>
        <groupId>com.solacesystems</groupId>
        <artifactId>sol-jcsmp</artifactId>
    </sharedLibrary>
    <sharedLibrary>
        <groupId>javax.jms</groupId>
        <artifactId>jms</artifactId>
    </sharedLibrary>
    <sharedLibrary>
        <groupId>javax.jms</groupId>
        <artifactId>javax.jms-api</artifactId>
    </sharedLibrary>

 

Add dependencies

    <dependency>
        <groupId>com.solacesystems</groupId>
        <artifactId>sol-jms</artifactId>
        <version>${solace.version}</version>
    </dependency>
    <dependency>
        <groupId>com.solacesystems</groupId>
        <artifactId>sol-common</artifactId>
        <version>${solace.version}</version>
    </dependency>
    <dependency>
        <groupId>com.solacesystems</groupId>
        <artifactId>sol-jcsmp</artifactId>
        <version>${solace.version}</version>
    </dependency>
    <dependency>
        <groupId>javax.jms</groupId>
        <artifactId>jms</artifactId>
        <version>${javax-jms-version}</version>
    </dependency>
    <dependency>
        <groupId>javax.jms</groupId>
        <artifactId>javax.jms-api</artifactId>
        <version>${javax.jms.api.version}</version>
    </dependency>

 

Add repository

<repository>
    <id>repository.jboss.org-public</id>
    <name>JBoss.org Maven repository</name>
    <url>https://repository.jboss.org/nexus/content/groups/public</url>;
</repository>

 

Final pom.xml will look like

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.mycompany</groupId>
    <artifactId>solace-service</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>mule-application</packaging>

    <name>solace-service</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <solace.version>10.3.1</solace.version>
        <javax-jms-version>1.1</javax-jms-version>
        <javax.jms.api.version>2.0.1</javax.jms.api.version>
        <app.runtime>4.3.0-20210119</app.runtime>
        <mule.maven.plugin.version>3.4.2</mule.maven.plugin.version>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-clean-plugin</artifactId>
                <version>3.0.0</version>
            </plugin>
            <plugin>
                <groupId>org.mule.tools.maven</groupId>
                <artifactId>mule-maven-plugin</artifactId>
                <version>${mule.maven.plugin.version}</version>
                <extensions>true</extensions>
                <configuration>
                    <sharedLibraries>
                        <sharedLibrary>
                            <groupId>org.mule.connectors</groupId>
                            <artifactId>mule-jms-connector</artifactId>
                        </sharedLibrary>
                        <sharedLibrary>
                            <groupId>com.mycompany</groupId>
                            <artifactId>solace-simple-01</artifactId>
                        </sharedLibrary>
                        <sharedLibrary>
                            <groupId>com.solacesystems</groupId>
                            <artifactId>sol-jms</artifactId>
                        </sharedLibrary>
                        <sharedLibrary>
                            <groupId>com.solacesystems</groupId>
                            <artifactId>sol-common</artifactId>
                        </sharedLibrary>
                        <sharedLibrary>
                            <groupId>com.solacesystems</groupId>
                            <artifactId>sol-jcsmp</artifactId>
                        </sharedLibrary>
                        <sharedLibrary>
                            <groupId>javax.jms</groupId>
                            <artifactId>jms</artifactId>
                        </sharedLibrary>
                        <sharedLibrary>
                            <groupId>javax.jms</groupId>
                            <artifactId>javax.jms-api</artifactId>
                        </sharedLibrary>
                    </sharedLibraries>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.mule.connectors</groupId>
            <artifactId>mule-http-connector</artifactId>
            <version>1.5.23</version>
            <classifier>mule-plugin</classifier>
        </dependency>
        <dependency>
            <groupId>org.mule.connectors</groupId>
            <artifactId>mule-sockets-connector</artifactId>
            <version>1.2.0</version>
            <classifier>mule-plugin</classifier>
        </dependency>
        <dependency>
            <groupId>org.mule.connectors</groupId>
            <artifactId>mule-jms-connector</artifactId>
            <version>1.7.1</version>
            <classifier>mule-plugin</classifier>
        </dependency>
        <dependency>
            <groupId>com.mycompany</groupId>
            <artifactId>solace-simple-01</artifactId>
            <version>1.0.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>com.solacesystems</groupId>
            <artifactId>sol-jms</artifactId>
            <version>${solace.version}</version>
        </dependency>
        <dependency>
            <groupId>com.solacesystems</groupId>
            <artifactId>sol-common</artifactId>
            <version>${solace.version}</version>
        </dependency>
        <dependency>
            <groupId>com.solacesystems</groupId>
            <artifactId>sol-jcsmp</artifactId>
            <version>${solace.version}</version>
        </dependency>
        <dependency>
            <groupId>javax.jms</groupId>
            <artifactId>jms</artifactId>
            <version>${javax-jms-version}</version>
        </dependency>
        <dependency>
            <groupId>javax.jms</groupId>
            <artifactId>javax.jms-api</artifactId>
            <version>${javax.jms.api.version}</version>
        </dependency>
    </dependencies>

    <repositories>
        <repository>
            <id>anypoint-exchange-v2</id>
            <name>Anypoint Exchange</name>
            <url>https://maven.anypoint.mulesoft.com/api/v2/maven</url>
            <layout>default</layout>
        </repository>
        <repository>
            <id>mulesoft-releases</id>
            <name>MuleSoft Releases Repository</name>
            <url>https://repository.mulesoft.org/releases/</url>
            <layout>default</layout>
        </repository>
        <repository>
            <id>repository.jboss.org-public</id>
            <name>JBoss.org Maven repository</name>
            <url>https://repository.jboss.org/nexus/content/groups/public</url>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>mulesoft-releases</id>
            <name>mulesoft release repository</name>
            <layout>default</layout>
            <url>https://repository.mulesoft.org/releases/</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>

</project>

 

Now drag and drop JMS On New Message Component and click on add connector configuration

 

Select Generic Connection

 

Add the Connection Factory JNDI, JNDI Initial factory, Soalce_JMS_VPN key and JNDI provider url as per the configuration noted while creating the Solace environment

We have to use username:password@ in provider url

 

Provide the username and password as well

 

Once done click on test connection

 

JMS Configuration will look like

<jms:config name="Solace" doc:name="JMS Config" doc:id="01e212f2-1377-4c3a-885b-7ebd65bce7c4">
    <jms:generic-connection username="solace-cloud-client" password="***********">
        <jms:connection-factory>
            <jms:jndi-connection-factory connectionFactoryJndiName="/jms/cf/default">
                <jms:custom-jndi-name-resolver>
                    <jms:simple-jndi-name-resolver jndiInitialFactory="com.solacesystems.jndi.SolJNDIInitialContextFactory" jndiProviderUrl="tcps://solace-cloud-client:[email protected]:55443">
                        <jms:jndi-provider-properties>
                            <jms:jndi-provider-property key="Solace_JMS_VPN" value="mulesy_solace_broker"/>
                        </jms:jndi-provider-properties>
                    </jms:simple-jndi-name-resolver>
                </jms:custom-jndi-name-resolver>
            </jms:jndi-connection-factory>
        </jms:connection-factory>
    </jms:generic-connection>
</jms:config>

 

Sample Mule Application – solace-service

 

  
Thank you for taking out time to read the above post. Hope you found it useful. In case of any questions, feel free to comment below. Also, if you are keen on knowing about a specific topic, happy to explore your recommendations as well.
 
For any latest updates or posts on our website, you can follow us on LinkedIn. Look forward to connecting with you there.


Share this:
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments