How to create a custom connector using Mule SDK | MuleSoft Blog (2023)

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

(Video) Kochi Mulesoft Meetup #8 - Creating Custom Connector using Mule SDK

Learn why we are the Leaders in API management and iPaaS

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:

(Video) How to Develop Custom Connector Using JAVA SDK in MuleSoft || #MuleSoft #Salesforce #FaridabadMeetup

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

How to create a custom connector using Mule SDK | MuleSoft Blog (1)

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

How to create a custom connector using Mule SDK | MuleSoft Blog (2)

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.

(Video) How to build a MuleSoft connector to Amazon Polly Service, synthesizing text into speech

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
How to create a custom connector using Mule SDK | MuleSoft Blog (3)
How to create a custom connector using Mule SDK | MuleSoft Blog (4)

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:

How to create a custom connector using Mule SDK | MuleSoft Blog (5)

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.

(Video) VirtualMuleys#40: Using the Mule 4 Java SDK to build a Connector

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);}
How to create a custom connector using Mule SDK | MuleSoft Blog (6)

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>
How to create a custom connector using Mule SDK | MuleSoft Blog (7)

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.

How to create a custom connector using Mule SDK | MuleSoft Blog (8)
How to create a custom connector using Mule SDK | MuleSoft Blog (9)

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.

(Video) JSON Logger – Part I | Deploying to Anypoint Exchange | MuleSoft

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.

How to create a custom connector using Mule SDK | MuleSoft Blog (10)

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.

What is the process to create a connector using REST connect MuleSoft? ›

Getting Started
  1. 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.
  2. Usage Reports.
  3. Browser Support.
  4. Glossary.
  5. Contribute to MuleSoft Documentation.

How do I configure file connector in Mule 4? ›

File Connector Examples - Mule 4
  1. Read a File. Configure the Read operation to read a file at any point in the flow.
  2. Create a Directory. Configure the Create directory operation to create a directory of a given name.
  3. Write a File. ...
  4. List Files. ...
  5. Copy and Move Files. ...
  6. Trigger a Flow for a Newly Created or Updated File.

How do I create a custom connector in Mule SDK? ›

Creating a custom connector with Mule SDK
  1. Step #1: Command prompt.
  2. Step #2: Configure.
  3. Step #3 Import project.
  4. Step #4: Clean and install the project.
  5. Step #5: Update dependencies.
  6. Step #6: Add to Mule palette.
  7. Step 7: Install connector.
  8. Step #8: Create custom connector configuration.
Jul 14, 2021

How do you publish a custom connector? ›

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? ›

Getting Started
  1. 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.
  2. Usage Reports.
  3. Browser Support.
  4. Glossary.
  5. Contribute to MuleSoft Documentation.

What is the difference between publish and publish consume in Mule 4? ›

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? ›

Getting Started
  1. Prerequisites.
  2. Design an API Specification.
  3. Develop the API.
  4. Add Validation and Error Handling.
  5. Deploy the API to CloudHub.
  6. Operate the API.

What are the different types of connectors in MuleSoft? ›

Mulesoft connectors are reusable extensions that allow you to interface Mule apps with third-party APIs, databases, and standard integration protocols.
...
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? ›

6 Steps to Creating a Custom Connector
  1. Build your API. ...
  2. Secure your API. ...
  3. Describe the API and define the custom connector. ...
  4. Use your connector in a Logic App, Power Automate, or PowerApps app. ...
  5. Share your connector. ...
  6. Certify your connector.
Nov 27, 2019

What are file connectors in mule4? ›

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? ›

Using Anypoint Studio to Configure Database Connector 1.9 - Mule...
  1. Create a Mule project.
  2. Add the connector to your Mule project.
  3. Configure a source for the connector's flow.
  4. Add a connector operation to the flow.
  5. Configure a global element for the connector.

How do I add a custom connector to a solution? ›

Steps
  1. Click the solutions tab.
  2. Create a new solution or open an existing unmanaged solution.
  3. Click new then click Custom connector.
  4. A new tab opens to create a new custom connector.
  5. Once finished, click Save.
  6. Now it's ok to close the browser tab.
Sep 11, 2019

What is a custom connector? ›

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? ›

Getting Started
  1. 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.
  2. Usage Reports.
  3. Browser Support.
  4. Glossary.
  5. Contribute to MuleSoft Documentation.

What is the use of DevKit in mule 4? ›

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? ›

Before creating a connector, navigate to the new EAC from the Microsoft 365 admin center by clicking Exchange under the Admin centers pane.
...
For New EAC
  1. Click Next. ...
  2. Provide a name for the connector and click Next. ...
  3. Choose an option that determines when you want to use the connector, and click Next.
Feb 22, 2023

How do I create a Connect app? ›

Depending on your connected app use case, use these instructions to build your connected app.
  1. Configure Basic Connected App Settings. ...
  2. Enable OAuth Settings for API Integration. ...
  3. Configure a Connected App for the OAuth 2.0 Client Credentials Flow. ...
  4. Integrate Service Providers as Connected Apps with SAML 2.0.

How do I create API instance in MuleSoft? ›

Add a New API
  1. Log in to Anypoint Platform.
  2. In the navigation bar or the Anypoint Platform page, click API Manager.
  3. Click Add API and select Add new API.
  4. Select and configure your runtime from the following options: Flex Gateway. ...
  5. Click Next.
  6. Select an API from the following options: ...
  7. Click Next.
  8. Configure the endpoint.

What is HTTP connector in MuleSoft? ›

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? ›

How to create a custom function in Excel
  1. Open VBE by pressing Alt+F11 on a PC or FN+ALT+F11 on a Mac.
  2. Locate "Insert."
  3. Select "Module."
  4. Type "Function," then specify what function you want to use.
  5. Confirm Excel automatically included "End Function."
  6. Update the code with any arguments and value specifications.
Apr 25, 2022

How do you write a custom function? ›

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? ›

Using a custom function
  1. Click the cell where you want to use the function.
  2. Type an equals sign ( = ) followed by the function name and any input value — for example, =DOUBLE(A1) — and press Enter.
  3. The cell will momentarily display Loading... , then return the result.
Feb 7, 2023

How do I Import a connector into MuleSoft? ›

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? ›

Add the Connector to Your Mule Project
  1. In the Mule Palette view, click (X) Search in Exchange.
  2. In Add Modules to Project, type salesforce in the search field.
  3. Click the connector name in Available modules.
  4. Click Add.
  5. Click Finish.

How do I create a custom connector for power automated? ›

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.

Videos

1. Mule 4 | Mulesoft Tutorials | How to integrate salesforce in Mule
(KLART Technologies)
2. AnyPoint Exchange is a Free Maven-Based Repository | MuleSoft Tutorial
(Jason Estevan)
3. Virtual Muleys: Custom File Logging Framework using the Mule 4 Java SDK
(VirtualMuleys)
4. Spotify Custom Connector Installation process in Mule4
(Jani Mohammad)
5. Getting Started with the Apache Kafka Connector | Integrations
(MuleSoft Videos)
6. Mule 4 | MuleSoft Tutorials |File connector in mule 4 | How to read file in MuleSoft
(KLART Technologies)
Top Articles
Latest Posts
Article information

Author: Aron Pacocha

Last Updated: 04/06/2023

Views: 6223

Rating: 4.8 / 5 (68 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Aron Pacocha

Birthday: 1999-08-12

Address: 3808 Moen Corner, Gorczanyport, FL 67364-2074

Phone: +393457723392

Job: Retail Consultant

Hobby: Jewelry making, Cooking, Gaming, Reading, Juggling, Cabaret, Origami

Introduction: My name is Aron Pacocha, I am a happy, tasty, innocent, proud, talented, courageous, magnificent person who loves writing and wants to share my knowledge and understanding with you.