Guide: MuleSoft Integration
Chapter
11

MuleSoft Connectors: Tutorial, Examples & Best Practices

Imagine using multiple software applications in your business, such as a database, Salesforce for customer data management, QuickBooks for accounting, and an internal inventory system. These systems need to talk to each other and exchange information. Manually moving data between them is often a headache because it is error-prone, slow, and hard to maintain.

That’s where MuleSoft comes in. It provides a platform that enables seamless connections between different systems through connectors. It acts like a ready-made bridge to connect your apps and automate data flow, saving time and reducing errors with minimal maintenance. But what if you have an ancient and unique system, such as an EJB server or another popular system, that doesn’t have an existing prebuilt connector? No problem: MuleSoft provides SDK support to build a custom connector.

This guide explains MuleSoft connectors, their work, and why you may want to use them. We also discuss different types of connectors, including custom ones.

Summary of key concepts about Mulesoft connectors

Concept Description
What are MuleSoft connectors? MuleSoft connectors are prebuilt integration components that allow Mule applications to talk to external systems.
Different types of connectivity with connectors MuleSoft connectors can create various types of connectivity, including software applications, database systems, and other protocols.
Advantages of Mulesoft connectors Connectors accelerate integration development by offering scalable, flexible, and reusable components that save time and reduce errors. Without them, developers must write complex code for every system they need to connect.
How connectors work Connectors can be used as inbound, message processors, or outbound endpoints.
Types of MuleSoft connectors There are three types of connectors: Anypoint Exchange connectors, partner connectors, and custom connectors.
What is a custom MuleSoft connector? A custom connector connects an old or unique system that MuleSoft does not directly support.
How to build a custom connector MuleSoft provides an SDK to build connectors via a Maven-based Java project.
Real-life examples Real-world examples include Salesforce integration using the Salesforce connector or SAP order management using the SAP connector.
Challenges and limitations A few challenges and limitations exist, like licensing costs, limited customization, performance bottlenecks, etc.
The future: even easier integrations Integration can be made easier by using AI-driven autoconfiguration. CurieTech AI is a strong candidate for this purpose.

{{banner-large-graph="/banners"}}

What are MuleSoft connectors?

All connectivity in Mule 4 is provided through MuleSoft connectors. Those are reusable, prebuilt integration components that allow Mule applications to talk to external systems, such as:

  • Enterprise systems (like SAP, IBM MQ)
  • SaaS platforms (like Salesforce, ServiceNow, Workday)
  • Databases (like MySQL, Oracle, PostgreSQL)
  • APIs (like REST and SOAP services)

Without connectors, developers would have to manually write complex integration code handling authentication, request validation and formatting, error handling, retries, etc. A connector hides all these details and abstracts all that complexity, so you can configure them instead of coding everything from scratch.

For example, we can use the Salesforce connector to execute create contact or update opportunity actions in Salesforce. Developers can simply drag and drop the Salesforce connector into their MuleSoft Anypoint Studio workflow and configure it properly without writing any code. The connector handles authentication, manages HTTP requests, OAuth tokens, JSON parsing, and error handling, significantly reducing development time.

MuleSoft Connectors: Tutorial, Examples & Best Practices

Different types of connectivity with connectors

You can use a connector to connect to another MuleSoft application, specific software, databases, and various types of protocols without knowing the protocol details.

Connect to another MuleSoft application

Say you have a Mule Restful `weather-api` application that you want to connect from another Mule application. The API is designed in the design center and published as a stable version in the company’s Mule Exchange.

MuleSoft Connectors: Tutorial, Examples & Best Practices

The weather-api application has a single api endpoint /weather that takes a single parameter, city. Now go to your application where you want to call this API, then hit the `Search in exchange` button in the Mule Palette. You should be able to see all published applications in exchange like this:

MuleSoft Connectors: Tutorial, Examples & Best Practices

After adding the weather-api as a dependency, you should be able to see a connector in Mule Palette containing all available operations:

MuleSoft Connectors: Tutorial, Examples & Best Practices

In the general property section, you can see the parameters of the API, and the basic settings section requires the connection configurations like this:

MuleSoft Connectors: Tutorial, Examples & Best Practices

Connect to a specific Software

You can use connectors to connect a Mule app to a specific software application and perform actions on the connected software application. For example, customers can have their SAP ERP and customer relationship management (CRM) systems. Using the SAP connector between SAP and CRM, they can automate their sales order processing. Similarly, the Salesforce connector can connect with other business applications, like data analytics and warehouse systems.

Connect to a database

Database connectors can connect a Mule app to one or more databases and perform actions. Using a Database connector, a Mule app can connect to any relational database engine. MuleSoft also has connectors for NoSQL databases like MongoDB. You can use the MongoDB connector to read, write, receive, and send files on the server.

Connect to Protocols

You can use connectors to send or receive data over various protocols to perform protocol operations without understanding the protocol. For example, an EJB connector can connect to an EJB server using the T3 Java RMI protocol. Using this connector, you can call remote EJB methods without knowing the details of the T3 protocol. Similarly, you can use Anypoint Connector for WebSockets to establish a bidirectional and full-duplex communication channel between a server and a client to send push notifications between them. 

Advantages of Mulesoft Connectors

MuleSoft connectors are essential for several reasons:

  • Reduced coding effort: A typical API integration can take several weeks of development work. With a connector, you can run it in a few hours or even a few minutes because no manual coding or development effort is involved.
  • Simplifies authentication: Connectors abstract the complexity of authentication by managing an internal state using an object store. The object store stores authentication tokens, including access and refresh tokens, and token metadata, such as the token expiration time. It also manages the token lifecycle, including invalidating a token, creating a new one after it expires, etc.
  • Reduced errors: Manual data transfer is prone to human errors. Prebuilt connectors are tested and certified by MuleSoft and the community, making them less likely to contain bugs than custom code written under a tight deadline. Connectors automate data synchronization, ensuring accuracy across systems. 
  • Metadata inference: Anypoint connectors can proactively infer metadata for the target system, making data identification and transformation easier.
  • Easier maintenance: When an external system changes, such as Salesforce updating its API version, the connector provider also updates the connector. You just need to upgrade the version from the application side instead of rewriting the integration again.
  • Scalability: Connectors handle connection pooling, retry policy, dead letter queues, and error handling, which are essential for scalability. These features make the connectors more reliable under load and enterprise-scale traffic.
  • Flexibility: MuleSoft connectors can be used in multiple integration scenarios like real-time APIs, batch jobs, event-driven flows, or streaming use cases. This flexibility makes the connectors suitable for small-scale applications to complex enterprise applications. 
  • Reduced cost: Building custom integration is expensive—connectors lower development cost by providing ready-made solutions.

How connectors work

Connectors can perform single or multiple actions in a Mule application. They can be placed in various locations within a Mule flow, depending on the capabilities of the connectors. A connector can act as any of the following:

  • An inbound endpoint (placed at the start of the flow). Connectors with sources, or triggers, can be placed at the beginning of a flow, starting it by receiving information from the connector’s resource. For example, when a Salesforce user updates a sales opportunity, a flow that begins with a Salesforce connector that listens to modified objects can receive the information and direct it to a database connector for processing. A few other examples are HTTP listeners or schedulers as sources for flows.
  • A message processor (placed in the middle of the flow). A widespread usage of connectors is executing operations that execute API calls or other actions on their associated systems, databases, or protocols. For example, you can use the Workday connector to create a position request in Workday or add a fund to the financial management service. Similarly, VM connectors can be used in the middle of a flow to consume messages from and publish messages to an asynchronous queue.
  • An outbound endpoint (placed at the end of the flow). An outbound endpoint receives the final payload data from the flow to consume.

Types of MuleSoft connectors

MuleSoft has a collection of connectors designed to provide virtually any integration solution, from common SaaS applications to particular, proprietary systems. These connectors are categorized into three primary types, each serving a specific purpose.

Anypoint Exchange connectors

Anypoint Exchange connectors are the backbone of the MuleSoft integration project. MuleSoft fully develops, tests, certifies, and supports them. These connectors are the most reliable option because they undergo rigorous testing to ensure they are robust, secure, and perform as expected within the Anypoint Platform. As an official product, these connectors come with full technical support, detailed documentation, and often dedicated forums for technical discussions. They are designed for the most common use cases across the global enterprise landscape.

Anypoint Exchange connectors are not just libraries but fully fledged components that understand the semantics of the target system. For example: 

  • The Salesforce connector is not just a generic REST client; it has built-in operations for standard Salesforce objects like accounts, opportunities, and leads. It handles Salesforce-specific authentication like OAuth2 with JWT tokens, token management, bulk operations, and API limits.
  • The SAP connector integrates with SAP ERP for order management and is a prime example of handling extreme complexity. The connector uses the SAP Java connector (JCo) library to communicate via SAP’s proprietary Remote Function Call (RFC) protocol, handle data type conversion (like SAP structure to Java objects), and manage stateful sessions by storing session info internally.
  • The database connector abstracts boilerplate code to create a database connection, connection pool, and different SQL dialects. You can write a generic SQL statement, and the connector handles the specifics of communication with Oracle, MySQL, or SQL servers via the appropriate JDBC driver.
  • The HTTP connector, one of the most widely adopted, provides versatile REST or SOAP API connectors.

Partner connectors

Partner connectors are developed by MuleSoft technology and system integration partners to extend integration capabilities and reach into specialized applications. These connectors are typically used in industry-specific insurance, telecom, or retail. They bring deep and insightful knowledge of that system’s API and business logic.

Primary support is provided by the partners who developed the connectors, not directly by MuleSoft. Although MuleSoft does not build these connectors, they must still pass the certification process to be listed in Anypoint Exchange, which ensures a minimum standard for security, stability, and usability within the platform.

A partner connector operates with the same seamless integration as an Anypoint Exchange connector. The only difference is that it is specialized and focused. Here are a couple of examples:

  • The Slack connector supports operations like sending a message, uploading a file, or creating a channel, making it extremely simple to automate notifications and workflows within a company’s Slack workspace. 
  • The Twilio connector allows operations like send-sms, make-call, or list messages, abstracting the underlying Twilio REST API. A developer doesn’t need to know the exact API endpoint or JSON message structure for a request. They just configure the connector with their credentials and use the intuitive operations.

Custom connectors

Custom connectors are the ideal solution for flexibility. They are built in-house by an organization’s developer or a third-party consultant to connect to a system without an existing connector. They are intended for mainframes, home-grown applications, or older technologies like EJB servers that were never designed with modern REST APIs.

How to build a custom connector

MuleSoft provides an SDK for building connectors through a Maven-based Java project. To build a custom connector, follow these steps.

Step 1: Set up a Maven project

The Mule SDK uses Maven to manage dependencies and build the connector Java project. Start by creating a new Maven project and ensuring that the Mule SDK dependency is included:

<dependency>
       <groupId>org.mule.sdk</groupId>
       <artifactId>mule-sdk-api</artifactId>
       <version>1.0.0</version>
   </dependency>

Step 2: Define the connector

The Mule SDK uses annotations to define the connector and its operations, parameters, and configurations. The following highlights a few important classes:

@Configuration(name = "my-config")
   public class MyConnectorConfig {
       @Parameter
       private String apiKey;
   }

   @Connector(name = "my-connector", friendlyName = "My Custom Connector")
   public class MyConnector {

       @Operation
       public String greet(@Config MyConnectorConfig config, String name) {
           return "Hello, " + name + "! Your API key is " + config.getApiKey();
       }
   }

Step 3: Build and test the connector in Anypoint Studio

Perform the following actions:

  • Build the project by running mvn clean install.
  • Open Anypoint Studio.
  • Create a new Mule project.
  • Add your connector JAR (in the `target` folder) to the project’s `lib` folder.
  • Install the connector and put it in your pom dependency
  • Use the connector in a flow and test its functionality.

Real-life examples

Anypoint Exchange offers hundreds of pre-built connectors that simplify the integration with popular applications and protocols. Real-world examples include Salesforce integration using the Salesforce connector or SAP order management using the SAP connector.

Salesforce and ERP synchronization

Many retail companies use Salesforce as their Customer relationship management (CRM) system to manage leads, opportunities, and customer interactions. These companies also use Enterprise Resource Planning (ERP) systems like SAP, NetSuite, or Oracle E-Business Suite to handle back-office operations such as order processing, inventory management, and finance. Without integration, these systems will work as silos, which leads to duplicate data entry, data inconsistency, and other issues. With MuleSoft, businesses can use the pre-built Salesforce connector and ERP connectors to automate flows to:

  • Create ERP customer records when new Salesforce contacts are added.
  • Update Salesforce when ERP orders are fulfilled.

CurieTech AI can be used here; it is an intelligent assistant built specifically for software developers. The coding agents of CurieTech AI create these integrations. 

MuleSoft Connectors: Tutorial, Examples & Best Practices

Now, describe the integration in plain English text and select an appropriate configuration like `Enable MUnit test` 

MuleSoft Connectors: Tutorial, Examples & Best Practices

Whenever a sales rep creates or updates a customer in Salesforce, MuleSoft automatically syncs that data with the ERP to create or update a corresponding customer, like this:

MuleSoft Connectors: Tutorial, Examples & Best Practices

In this integration, the Salesforce connector and the SAP connector are used. The dependency can be found in pom.xml with version and other details:

<dependencies>
		<!-- Salesforce Connector -->
		<dependency>
			<groupId>com.mulesoft.connectors</groupId>
			<artifactId>mule-salesforce-connector</artifactId>
			<version>10.18.0</version>
			<classifier>mule-plugin</classifier>
		</dependency>
		
		<!-- SAP Connector -->
		<dependency>
			<groupId>com.mulesoft.connectors</groupId>
			<artifactId>mule-sap-connector</artifactId>
			<version>5.9.12</version>
			<classifier>mule-plugin</classifier>
		</dependency>
	...	
</dependencies>

{{banner-large="/banners"}}

SAP order processing

In many enterprises, SAP is the backend record system for order management, inventory, billing, and supply chain processing. However, front-end applications like e-commerce or mobile apps must interact with the SAP system to place orders, check availability, or track deliveries.

CurieTech AI can create this integration automatically. It uses artificial intelligence to automatically handle many time-consuming, repetitive jobs in building a MuleSoft application. These include writing code, creating diagrams for technical documentation, and generating tests to produce high-standard tested code. 

In CurieTech AI, we can perform this integration using a coding agent by describing the task in plain English. Explain the task straightforwardly: “Process to do SAP Order Processing using the SAP connector.”

MuleSoft Connectors: Tutorial, Examples & Best Practices

After clicking the `Coder` code generator the following screen will show up:

MuleSoft Connectors: Tutorial, Examples & Best Practices

A sample configuration automatically generates a complete Order Management project using the SAP connector.

MuleSoft Connectors: Tutorial, Examples & Best Practices

Then, download the project and import it into Anypoint Studio. Set up the SAP connector parameter in the property file and test the AI-generated order management project.

MuleSoft Connectors: Tutorial, Examples & Best Practices

The SAP dependency  can be found in pom.xml with version and other details:

<dependencies>
		<!-- SAP Connector -->
		<dependency>
			<groupId>com.mulesoft.connectors</groupId>
			<artifactId>mule-sap-connector</artifactId>
			<version>5.9.12</version>
			<classifier>mule-plugin</classifier>
		</dependency>
	...	
</dependencies>

The order management flow generated above is a bit complex, so we can use the diagram generator provided by the Documentation agent to draw a sequence diagram of the flow to understand it better.

MuleSoft Connectors: Tutorial, Examples & Best Practices

The output of the AI agent is like this:

MuleSoft Connectors: Tutorial, Examples & Best Practices

Now we can generate tests using the MUnit test generator of the Testing agent.

MuleSoft Connectors: Tutorial, Examples & Best Practices

MuleSoft Connectors: Tutorial, Examples & Best Practices

Here is the test of that order flow:

MuleSoft Connectors: Tutorial, Examples & Best Practices

Challenges and limitations

While MuleSoft connectors are robust, they’re not magic bullets; they come with some challenges: 

  • Licensing costs: Advanced connectors may require paid licenses and might only be available in MuleSoft’s Enterprise edition.
  • API changes: If the target system updates its API, you might need to update or reconfigure the connector.
  • Connector building skills: Building a connector requires Maven-based Java application building expertise and familiarity with the Mule SDK.
  • Performance awareness: Some connectors introduce slowness and latency if not configured correctly. For example, the connector might need a connection pool for best performance, or Mule’s batch processing feature with connectors.

{{banner-large-table="/banners"}}

Conclusion

MuleSoft connectors are the building blocks of powerful system integration. They eliminate major integration bottlenecks by providing a pre-built solution for the most common systems, like Salesforce, SAP, and databases, or by developing custom ones for unique or old systems. The benefits of connectors are clear: faster development, fewer errors, and simpler maintenance. As AI-driven integration evolves, the future promises even faster, smarter, and more resilient connectivity. Mule connectors are a strategic necessity today so businesses can stay ahead in an interconnected digital world.

Continue reading this series