DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Configuring a Shopify MuleSoft Connector
  • Build a Query in MuleSoft With Optional Parameters
  • Handle HL7 MLLP Messages With Mule 4
  • SharePoint Integration With MuleSoft

Trending

  • The Perfection Trap: Rethinking Parkinson's Law for Modern Engineering Teams
  • A Guide to Auto-Tagging and Lineage Tracking With OpenMetadata
  • Agile’s Quarter-Century Crisis
  • The Future of Java and AI: Coding in 2025
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. How to Build a Custom Connector in MuleSoft

How to Build a Custom Connector in MuleSoft

In this tutorial, learn how to build and test your own custom Mule Flow connector to send and receive data in Anypoint Studio.

By 
Santhosh Ramagiri user avatar
Santhosh Ramagiri
·
Aug. 24, 17 · Tutorial
Likes (6)
Comment
Save
Tweet
Share
22.3K Views

Join the DZone community and get the full member experience.

Join For Free

Anypoint Connectors helps to integrate the Mule applications with third-party APIs and standard integration protocols, providing a means to access web services and resources. Use the connectors within Mule flows to send and receive data over a protocol or using an API. In computer programming, string concatenation is the operation of joining character strings end-to-end. For example, the concatenation of "Hello" and "MuleSoft" is "HelloMuleSoft."

Objective

String concatenation is a binaryinfix operator. The + (plus) operator is often overloaded to denote concatenation for string arguments: "Hello " + "MulesSoft" has the value "Hello MuleSoft."

Prerequisites

  • Java JDK Version 8
  • Apache Maven-3.3.9
  • Anypoint Studio-3.8
  • Anypoint Devkit Plugin-1.1.5
  • Devkit plugin

Creating a Connector

  • Click on the Add View icon in the upper right corner of Anypoint Studio, select Devkit and click on OK.Image title
  • Now you can see the Devkit view has been enabled.

Image title

  • Click File>New> and then select Anypoint Connector Project to create a new project to build the connector.

Image title

  • Select SDK Based, as this connector is built using Java library, and click Next.

Image title

  • Give the name for the connector in the Connector name field and click Finish. Upon clicking the Finish button, Anypoint Studio will download all the dependencies that help in building the connector.

Image title

  • Now the connector project will be created with all the folders and folder structure to develop the connector. After creating the project, the folder structure of the project will be as shown below.

Image title

  • When the project is created, a sample code will be automatically given in the project. This code can be found in DemoConnector.java  and ConnectorConfig.java classes. The DemoConnector.java class contains the code that adds the functionality to the connector. The ConnectorConfig.java class contains code that is related to the configuration of the connector, like connection details. If the connector requires the fields for connection, then these two classes will be interlinked. These classes can be found in two separate packages. DemoConnector.java will be present in org.mule.modules.demo and ConnectorConfig.java in the org.mule.modules.demo.config package. Both the packages can be found under the src/main/java folder.

  • The DemoConnector.java class contains the code that adds the functionality to the connector. You can see the code that is generated in this class when the project is created.

Image title

You can edit the code in this class as per the functionality of the connector. In this class, three packages will be automatically imported for the annotations which will be used in the class. The three packages can be seen below:

  • org.mule.api.annotations.Config;

  • org.mule.api.annotations.Connector;

  • org.mule.api.annotations.Processor;

Here, the return statement gives the output as "Hello Eaiesb How are you?"

  • The ConnectorConfig.java class contains code that is related to the configuration, like connection details. You can see the code that is generated in this class when the project is created. If your connector does not require any configuration, you can remove all the code in this class which will not be used in connector configuration.

Image title

  • To build the connector, click on the connector project Demo-connector> select Anypoint Connector and select Build Connector.

Image title

  • It will be clear that the connector has been successfully built when you see the BUILD SUCCESS message in the console area.Image title
  •  Now the connector needs to be installed so that it can be used in Mule flows to build Mule applications. To install the connector, click on connector project Demo-connector> Select   Anypoint Connector and Select Install or Update.Image title
  • It will be clear that the connector has been successfully installed when you see the BUILD SUCCESS message in the console area.

Image title

  • Now go back to Mule Design mode by selecting Mule Design at the upper right corner of Anypoint Studio to test the connector.

Image title

  • In Mule Design mode, if you search for the connector with its name, you can find the connector if it is successfully installed.Image title

Connector Testing

  • To test the connector, build a Mule application. To create the Mule application, click on File>New> Mule Project.Image title

  • Now the Mule project will be created. Drag and drop an HTTP palette onto the process canvas. Here, I am using HTTP as the source, but you can have any process as the source to start the Mule flow. Configure HTTP by providing the port number followed by the demo connector.Image title
  • Now configure the demo connector as shown below.Image title
  • Run the Mule application. Click on the process canvas and select Run project demo.Image title
  • If the application is successfully deployed, you can see the DEPLOYED message in the console area.

Image title

  • Now we hit the HTTP connector using Postman and the below message is shown.

Image title

In the same way, you can do other Operations on strings as of concatenation.

Thanks for reading this post.

Connector (mathematics) Build (game engine) MuleSoft

Opinions expressed by DZone contributors are their own.

Related

  • Configuring a Shopify MuleSoft Connector
  • Build a Query in MuleSoft With Optional Parameters
  • Handle HL7 MLLP Messages With Mule 4
  • SharePoint Integration With MuleSoft

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!