Reading Time: 14 minutes
Anypoint Connectors provide a connection between aMuleflow and an external system — such as any source of content, database, protocol, or API.While there are thousands of out-of-the-box connectors in Exchange, sometimes you need a custom connector to meet your specific needs.
In some situations, you may not find the appropriate connector to integrate your systems or the connector you need lacks a specific functionality you need —such as error handling or custom logging —that you’ll need to reuse for multiple projects.
latest report
Learn why we are the Leaders in API management and iPaaS
Read reports
This blog post will show you how to create your own custom connector using the new Mule SDK platform for Mule Runtime 4.
Prerequisites:
This blog assumes you are familiar with Anypoint Studio 7+ and have installed the appropriate versions of JDK, Anypoint Studio 7+, and Maven as specified in. See more on how to set up your development environment.
Creating a custom connector with Mule SDK
To create the project for the connector, run the command below in the command prompt where you want to create the project. Since there is currently no way to create connector projects from Anypoint Studio, we need to use a Maven archetype.
Step #1: Command prompt
Open command prompt/git bash where you want to create the project and run the below command as shown below:
mvn org.mule.extensions:mule-extensions-archetype-maven-plugin:generate
Step #2: Configure
Once you execute the above command it will ask you to provide the below configurations:
- Name of the extension
- Extension’s groupId
- Extension’s artifactId
- Extension’s version
- Extension’s main package
Provide those details as below:
- Enter the name of the extension: DemoConnector
- Enter the extension’s groupId: com.Demo.muleConnector
- Enter the extension’s artifactId: mulesoft-demo-connector
- Enter the extension’s version: 1.0.0
- Enter the extension’s main package: org.mule.extension.Demo
Once the build is successful, go to your folder and you will find a connector package with the artifact-id.
Step #3 Import project
Import the project to your workspace.

You’ll find the following class and folder structure. In this section, we’ll outline what you’ll find in each folder:

src/main/java folder
This folder contains the source Java files for your connector, including the skeleton Java files for operations and connection configuration. Additional supporting classes should be stored here as well.
Once we open this project in Anypoint Studio there will be a number of classes, which will be annotated with Mule SDK annotations as seen below:
- <connector-name>Extension.java: This class identifies the various properties of your connector. In Mule 4 a connector is nothing but an extension. This class would identify which is the configuration class, which are the operation classes.
- <connector-name>Configuration.java: This contains all the information that you want from the global configuration of the Connector.
- <connector-name>Connection.java: The connection class is responsible for handling the connection and in our case, most of the actual coding will be here.
- <connector-name>ConnectionProvider.java: This class is used to manage and provide the connection with the target system.
The connection provider must implement one of the connection providers available in Mule. The options are PoolingConnectionProvider, CachedConnectionProvider, and ConnectionProvider.
- <connector-name>Operations.java: This is the class where you define all of the necessary operations. There can be multiple operation class files.
src/main/resources folder
The resources folder contains non-code resources accessed by your connector. This folder is empty when you initially create the project.
src/test/java folder
The Java folder inside the test contains the Java source for the test files for your connector, including the skeleton JUnit test case.
src/test/resources folder
Contains non-code resources accessed by your tests. This folder contains a skeleton Mule configuration file for running tests.
POM File
Based on the archetype used to create the project, Maven generates the Project Object Model (POM) file. Maven uses the pom.xml file to keep track of all dependencies needed to build a project, including the dependencies’ version number and location. You may have to add items to the POM file during the connector development process to pull in additional libraries and add steps to the build process.
Step #4: Clean and install the project
Now go to your workspace and run the below command to build the jar:
mvn clean install –DskipTests


Step #5: Update dependencies
Now go to your Mule application (project) where you need to install the connector and update the dependency as shown below.
<dependency><groupId> com.Demo.muleConnector</groupId> <artifactId> mulesoft-demo-connector</artifactId><version>1.0.0</version> <classifier>mule-plugin</classifier></dependency>
Step #6: Add to Mule palette
Once you add the dependency, click on save so that the connector will add to your Mule palette as shown below:

Public methods are exposed as operations. If we are defining our method as public, that operation will be visible in Mule palette which can be used in custom connectors. Every public method will be taken as an extension operation.
The private methods are not exposed as operations. If we are defining our method as private, that operation will not be visible in Mule Palette.
If you want to set up the custom configuration in your connectors, use the configuration annotation and a connection annotation for the connection instance to perform some action.
/*** Example of an operation that uses the configuration and a connection instance to perform some action.*/@MediaType(value = ANY, strict = false)public String retrieveInfo(@Config BasicConfiguration configuration, @Connection BasicConnection connection){return "Using Configuration [" + configuration.getConfigId() + "] with Connection id [" + connection.getId() + "]";}
If we don’t want to use any configuration in our connector we will just pass the parameters to the function.
/*** Example of a simple operation that receives a string parameter and returns a new string message that will be set on the payload.*/@MediaType(value = ANY, strict = false)public String sayHi(String person) {return buildHelloMessage(person);}/*** Private Methods are not exposed as operations*/private String buildHelloMessage(String person) {return "Hello " + person + "!!!";}
/*** Example of a simple operation that receives a string parameter and returns a new string message that will be set on the payload.*/@MediaType(value = ANY, strict = false)public String sayHi(String person, String person2) {return buildHelloMessage(person, person2);}

After adding the parameter, update the connector version from 1.0.0 to 1.0.1 in connector pom.xml and rerun the mvn clean install –DskipTests.
Step 7: Install connector
Now add the connector version in application pom.xml where you want to install the connector and save so that it will be updated and displayed as below:
Connector pom.xml – (POM File in Custom Connector)
<?xml version="1.0" encoding="UTF-8" standalone="no"?><project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.Demo.muleConnector</groupId><artifactId>mulesoft-demo-connector</artifactId><version>1.0.1 </version><packaging>mule-extension</packaging><name>Demo Extension-Project</name><parent><groupId>org.mule.extensions</groupId><artifactId>mule-modules-parent</artifactId><version>1.1.3</version></parent></project>
Sample Application pom.xml (POM File – where we are using the Custom Connector)
<dependency><groupId>com.Demo.muleConnector</groupId><artifactId>mulesoft-demo-connector</artifactId><version>1.0.1 </version> <classifier>mule-plugin</classifier></dependency>

Step #8: Create custom connector configuration
If we want to create any configuration in our custom connector, please follow the below steps:
/*** Example of an operation that uses the configuration and a connection instance to perform some action.*/@MediaType(value = ANY, strict = false)public String retrieveInfo(@Config DemoConfiguration configuration, @Connection DemoConnection connection){return "Using Configuration [" + configuration.getConfigId() + "] with Connection id [" + connection.getId() + "]";}
Step #9: Create configuration and connection class
We will create the object of configuration and connection class.


There is one field for configuration and two fields for connection as in the screenshot below:
/*** This class represents an extension configuration, values set in this class are commonly used across multiple* operations since they represent something core from the extension.*/@Operations(DemoOperations.class)@ConnectionProviders(DemoConnectionProvider.class)public class DemoConfiguration {@Parameterprivate String configId;public String getConfigId(){return configId;}}
/*** A parameter that is always required to be configured.*/@Parameterprivate String requiredParameter;/*** A parameter that is not required to be configured by the user.*/@DisplayName("Friendly Name")@Parameter@Optional(defaultValue = "100")private int optionalParameter;
Step #10: Change display name
If we want to change the display name we can update the above “DisplayName” annotation. If we want to make field value as optional mark “optional annotation.” If you want to pass the default value you can pass as shown above.
Using this same method, we can increase or decrease the number of parameters.
If we want to create a connection using the mentioned parameters we can define in the connection class.

In this blog, we learned how to create a custom connector in Mule 4. These types of connectors are synchronized, so we have to decide on the functionality of the reusable connector. Join an upcoming Meetup event for more how-tos.
FAQs
How do I add a custom connector to Anypoint studio? ›
However to install a connector, you need to first open Anypoint Studio. Anypoint Exchange icon in the taskbar. When Exchange opens, search for the connector to install, click Install, and follow the prompts to install the connector.
How do I publish a custom connector in Mule 4? ›Steps to Publish the Custom Connector
Copy the organization ID. Modify the groupId of the Maven project to be your Organization ID in your Java SDK project's pom. xml. Add the Maven facade as a repository in the distribution management section of your project's POM file.
- Build an API from Start to Finish. Prerequisites. Design an API Specification. Develop the API. Add Validation and Error Handling. Deploy the API to CloudHub. Operate the API.
- Usage Reports.
- Browser Support.
- Glossary.
- Contribute to MuleSoft Documentation.
- Read a File. Configure the Read operation to read a file at any point in the flow.
- Create a Directory. Configure the Create directory operation to create a directory of a given name.
- Write a File. ...
- List Files. ...
- Copy and Move Files. ...
- Trigger a Flow for a Newly Created or Updated File.
- Step #1: Command prompt.
- Step #2: Configure.
- Step #3 Import project.
- Step #4: Clean and install the project.
- Step #5: Update dependencies.
- Step #6: Add to Mule palette.
- Step 7: Install connector.
- Step #8: Create custom connector configuration.
To make a custom connector publicly available for all users in Logic Apps, Power Automate, and Power Apps, submit your connector to Microsoft for certification. Microsoft will review the connector and, if it meets certification criteria, approve it for publishing.
How do I create a connected app in MuleSoft? ›- Build an API from Start to Finish. Prerequisites. Design an API Specification. Develop the API. Add Validation and Error Handling. Deploy the API to CloudHub. Operate the API.
- Usage Reports.
- Browser Support.
- Glossary.
- Contribute to MuleSoft Documentation.
Publish - Used for publish message into the queue, dont wait for resposne, after publishing message then main thread execute next process in the flow or sub flow. Publish Consume - Used for publish message into the queue and wait for resposne from vm listner flow.
How do I create a custom function in Mule 4? ›- Prerequisites.
- Design an API Specification.
- Develop the API.
- Add Validation and Error Handling.
- Deploy the API to CloudHub.
- Operate the API.
...
Different types of Mule Connectors
- Salesforce Connector.
- SAP Connector.
- Amazon S3 Connector.
- Adobe Marketo Connector.
- Ajax connector.
- Amazon Kinesis Data Streams Connector.
What is the purpose to create a connector using rest connect? ›
A REST API connector allows users the flexibility to connect to any existing REST API and quickly extract the necessary data.
How do I set up an API connector? ›- Build your API. ...
- Secure your API. ...
- Describe the API and define the custom connector. ...
- Use your connector in a Logic App, Power Automate, or PowerApps app. ...
- Share your connector. ...
- Certify your connector.
Anypoint Connector for File (File Connector) manages files and folders on a locally mounted file system. The connector's main features include: The ability to read files or fully list directory contents on demand.
How do you connect the SAP connector in Mule 4? ›In the Mule Palette view, click (X) Search in Exchange. In the Add Dependencies to Project window, type sap in the search field. Click SP Connector in Available modules. Click Add.
How do I use a database connector in Mule 4? ›- Create a Mule project.
- Add the connector to your Mule project.
- Configure a source for the connector's flow.
- Add a connector operation to the flow.
- Configure a global element for the connector.
- Click the solutions tab.
- Create a new solution or open an existing unmanaged solution.
- Click new then click Custom connector.
- A new tab opens to create a new custom connector.
- Once finished, click Save.
- Now it's ok to close the browser tab.
A custom connector is a wrapper around a REST API (Logic Apps also supports SOAP APIs) that allows Logic Apps, Power Automate, or Power Apps to communicate with that REST or SOAP API. These APIs can be: Public (visible on the public internet) such as Spotify, Slack, Rackspace, or an API you manage.
How to create mule plugin? ›- Build an API from Start to Finish. Prerequisites. Design an API Specification. Develop the API. Add Validation and Error Handling. Deploy the API to CloudHub. Operate the API.
- Usage Reports.
- Browser Support.
- Glossary.
- Contribute to MuleSoft Documentation.
Anypoint Connector DevKit (DevKit), enables the development of Anypoint Connectors. An Anypoint Connector is an extension module to the MuleSoft Anypoint Platform that facilitates communication between third-party systems' APIs and Mule applications.
How do I create an online connector in exchange? ›...
For New EAC
- Click Next. ...
- Provide a name for the connector and click Next. ...
- Choose an option that determines when you want to use the connector, and click Next.
How do I create a Connect app? ›
- Configure Basic Connected App Settings. ...
- Enable OAuth Settings for API Integration. ...
- Configure a Connected App for the OAuth 2.0 Client Credentials Flow. ...
- Integrate Service Providers as Connected Apps with SAML 2.0.
- Log in to Anypoint Platform.
- In the navigation bar or the Anypoint Platform page, click API Manager.
- Click Add API and select Add new API.
- Select and configure your runtime from the following options: Flex Gateway. ...
- Click Next.
- Select an API from the following options: ...
- Click Next.
- Configure the endpoint.
The HTTP connector has a Listener operation that receives requests over HTTP or HTTPS protocol. Receiving a request generates a Mule event and passes the request body to the next element of the flow as the message payload. You can refer to parts of the Event output.
What is the difference between JMS and VM in MuleSoft? ›Within the application, if you send the control from one flow to another flow we use VM. VM can be used as both inbound and outbound. Outside the application, for example, A application want to send something to B application(external application) there we use JMS.
What is the difference between flow reference and VM in mule? ›VM endpoints enable message redelivery strategies to be configured in your exception handling blocks — this is not possible with flow-refs. VMs can do this because they internally use a queue to hold messages while flow-refs are similar to simple method calls.
What is postman in mule? ›Postman has become the standard for any developer working with APIs. It provides an intuitive interface that allows developers to easily configure, interact, and test APIs.
How do I create a custom function? ›- Open VBE by pressing Alt+F11 on a PC or FN+ALT+F11 on a Mac.
- Locate "Insert."
- Select "Module."
- Type "Function," then specify what function you want to use.
- Confirm Excel automatically included "End Function."
- Update the code with any arguments and value specifications.
A custom function must start with a Function statement and end with an End Function statement. In addition to the function name, the Function statement usually specifies one or more arguments. You can, however, create a function with no arguments.
How do you use custom functions? ›- Click the cell where you want to use the function.
- Type an equals sign ( = ) followed by the function name and any input value — for example, =DOUBLE(A1) — and press Enter.
- The cell will momentarily display Loading... , then return the result.
They are just added to a Mule 4 application project. There are two methods to use the connector. Add it to the project from Anypoint Exchange, by using the palette "Search in Exchange..." option, or just add the Maven coordinates as a dependency to the project's pom. xml.
How do I install Salesforce connector in Anypoint studio? ›
- In the Mule Palette view, click (X) Search in Exchange.
- In Add Modules to Project, type salesforce in the search field.
- Click the connector name in Available modules.
- Click Add.
- Click Finish.
Sign in to Power Apps or Power Automate. On the left pane, select Data > Custom connectors. Select New custom connector, and then select Create from blank. Enter a name for the custom connector, and then select Continue.
What is MuleSoft custom connector? ›MuleSoft's Anypoint Connectors help to through various Protocols and APIs. Mulesoft has a range of inbuilt connectors connecting to various protocols like SFTP, FTP, JDBC, etc. or to other SAAS systems like Salesforce and different Google and AWS services, plus many more.
How to configure Salesforce Connector MuleSoft? ›First, go to File -> New -> Mule Project then go to the Mule Palette. Add the HTTP module to your project, and drag the HTTP Listener into your flow. Set the port to 8081, the path to: /salesforce. Next, go to the Mule Palette, and add the Database Module to your project.
What is the difference between Kafka Connect and connector? ›Kafka Connect manages the Tasks ; the Connector is only responsible for generating the set of Tasks and indicating to the framework when they need to be updated. Source and Sink Connectors / Tasks are distinguished in the API to ensure the simplest possible API for both.
What is Kafka connect connectors? ›The Kafka Connect JMS Source connector is used to move messages from any JMS-compliant broker into Kafka. Elasticsearch Service Sink. The Kafka Connect Elasticsearch Service Sink connector moves data from Kafka to Elasticsearch. It writes data from a topic in Kafka to an index in Elasticsearch.