MuleSoft creates a great opportunity of reusing the readily available connectors but in some cases, the connector might not be available for connecting to a particular system. We need to write custom logic like spring beans/Java code to connect to it. However, if we don’t want to include the same logic in every API integration which implements the requirement, we can create a custom connector. There are broadly two types of custom connectors:
- Java SDK
- XML SDK.
This article will look at the XML SDK , which provides an easier learning curve than Java SDK and is more like developing a Mule application.
Anatomy of XML SDK
- Operations – An operation in XML SDK is relatable to a Java method with a set number of arguments required (can have zero arguments as well), a body to process, and an output.
- Properties – To define a global configuration, we can use properties inside a connector. When specified, a user can create a global configuration with defined properties.
Creating a custom connector
The first step while creating a custom connector is to generate a skeleton project.
Run the below command in the command prompt.
|-DarchetypeGroupId||Group ID of Archetype in the Mule repository|
|-DarchetypeArtifactId||Artifact ID of the Archetype in the Mule repository|
|-DarchetypeVersion||Version of the aerchetype|
|-DgroupId||Group ID of the user’s Mule application|
|-DartifactId||Artifact Id for user’s application/module|
|-DmuleConnectorName||Name of the connector|
Once generated, import it in MuleSoft Anypoint Studio. The structure looks like below:
module-Hello.xml contains the main logic implemented by the connector.
Here, we will write a simple connector with two operations. One to modify the incoming query parameter and second to return the sum of two numbers which will further pass in the parameters.
Operation to get sum of two numbers
Operation to modify the query param
To install the connector locally, run mvn clean install
To use the connector in project, add the dependency
Once done, the connector will be available in the Mule palette.
Add the operations in the flow as required. Below is the property view for each operation.
Mule XML-based SDK is a straightforward and efficient way to create a custom connector and fulfill any ad hoc requirements.
Find more MuleSoft Technical guides at Caelius Consulting MuleSoft Resource Centre.