Migrating Devkit Connectors to Mule 4 SDK

  • Written By WHISHWORKS
  • 12/04/2018

Mule is a lightweight integration runtime engine that powers Mule applications. Mule applications receive events, process them and route them to other endpoints, and Mule Runtime defines the rules on how event data is handled in each application.

The role of Connectors is to facilitate the integration of Mule applications with third-party APIs and standard integration protocols. These are the elements which receive or send messages between Mule and an external source.

MuleSoft already has more than 160 free, off-the-shelf connectors for some of the most frequently used integrations, along with a set of premium connectors like SAP, SalesForce, Siebel etc. These connectors will be migrated for Mule 4 by the companies that originally developed them, such as WHISHWORKS.

For all other systems, often users develop their own custom connectors to enable their integration with Mule and this is where an understanding of how to migrate to the new Mule 4 environment will be needed.

Mule 3 Devkit vs Mule 4 SDK

Up to now, to develop these custom connectors users would use the Anypoint Connector DevKit (DevKit), which is available for Mule 3.x Anypoint Studio as a plugin. DevKit is an annotations-based tool, with a wide set of available annotations to support its features. It also includes connector packaging tools.

Mule 4 uses Mule SDK to create custom connectors. Unlike Devkit, Mule SDK is not a code generator. It is rather a plain extension mechanism. Mule SDK also adds support for features like Transactions, Request-Response message sources, Dynamic configurations, Routers, Non-Blocking operations, Classloading isolation etc.

In Mule 4, Studio 7.x comes with Mule SDK already installed, however it only supports Mule 4.x connectors (and projects in general), because the structure of the project, export format, xml and scripting language are different from Mule 3.x.

Users must migrate Mule 3.x connectors to Mule 4.x manually, before they can be used in Studio 7.x.

How to migrate a Devkit Connector to Mule SDK:

A Mule 4 upgrade should be approached as a migration project. To migrate an existing Devkit Connector in order to be compatible with Mule 4 SDK, the changes below, at high level, need to be incorporated into the connector code base.Update pom file, to enable the Connector as Mule 4 extension

  • Update Packaging element

<packaging>mule-extension</packaging>

  • Update parent element

<parent>
<groupId>org.mule.extensions</groupId>
<artifactId>mule-modules-parent</artifactId>
<version>1.0.0</version>
</parent>Folder structure

The typical folder structure for Mule 4 Connector will be:

  • <Module>/api
  • <Module>/internal

Update Annotations and Params Classes

Remove/Add/Replace Classes w.r.t Mule 4 SDK

Mule 3.x ClassesActionMule 4 Replacements
org.mule.api.annotations.ConfigREPLACE org.mule.runtime.extension.api.annotation.param.Config
org.mule.api.annotations.ConnectorREPLACE org.mule.runtime.extension.api.annotation.Extension
org.mule.api.annotations.display.PathREPLACEorg.mule.runtime.extension.api.annotation.param.display.Path
org.mule.api.annotations.licensing.
RequiresEnterpriseLicense
REPLACEorg.mule.runtime.extension.api.annotation.
license.RequiresEnterpriseLicense
org.mule.api.MuleContextREPLACEorg.mule.runtime.core.api.MuleContext
org.mule.api.context.MuleContextAwareREPLACEorg.mule.runtime.core.api.context.MuleContextAware
org.mule.api.annotations.ProcessorREMOVE 
org.mule.api.annotations.param.DefaultREPLACEAttribute(defaultValue) of Optional
@Optional(defaultValue =
@ConnectREMOVE 
@DisconnectREMOVE   
@ValidateConnectionREMOVE 
@ConnectionKeyREMOVE 
@ConnectionManagementREMOVE 
@HandleREMOVE 
@HandlerREMOVE 
@RefOnlyREPLACE@ExpressionSupport(NOT_SUPPORTED) and
@ParameterDsl(allowInlineDefinition=false)
ConnectionExceptionREPLACEorg.mule.runtime.api.connection.ConnectionException
ConnectionProviderREPLACEorg.mule.runtime.api.connection.ConnectionProvider
OnExceptionREPLACEorg.mule.runtime.extension.api.annotation.OnException
TestConnectorREPLACEorg.mule.runtime.module.extension.
internal.runtime.connectivity.basic.TestConnector
@org.mule.api.annotations.TestConnectivity  REMOVE 
@org.mule.api.annotations.
ConnectionIdentifier
REMOVE 
@org.mule.api.ConnectionExceptionCodeREPLACEorg.mule.runtime.api.metadata.resolving.FailureCode
org.mule.util.IOUtilsREPLACEorg.mule.runtime.core.api.util.IOUtils
OperationsADDorg.mule.runtime.extension.api.annotation.Operations
ConfigurationADDorg.mule.runtime.extension.api.annotation.Configuration
ConnectionADDorg.mule.runtime.extension.api.annotation.param.Connection


Organise import statements (Remove old APIs and/or Add new APIs)

  • Remove All classes within Package org.mule.api

Refactor Class(es) into multiple classes as per basic model structure of Mule 4 SDK

  • Add *Extension class with below annotation at class level:

@Extension(name = “azure-storage”)

@Configurations(Config.class)

@RequiresEnterpriseLicense(allowEvaluationLicense = true)

  • Add below annotation for the processor methods

@MediaType(value = ANY, strict = false)

Unit Tests

  • Override getConfigFile() method to load the operation flow
  • Test Class Extends MuleArtifactFunctionalTestCase
  • Test Class name should be *Test*.java

Dependency software and versions:

Mule runtime | 4.1.0
Mule SDK | 1.0.0
Java | 1.8
AnyPoint Studio | 7.1.0
Maven | >3.3.9

If you would like to find out more about Mule 4 and how you can migrate your connectors and projects to the new version of MuleSoft’s Anypoint Platform, do give us a call at +44 (0)203 475 7980 or email us at marketing@whishworks.com

Other useful links:

Mule 4 and Studio 7 – a bird’s-eye view of what’s new

API Recipes with MuleSoft Anypoint Platform

MuleSoft Integration Services

Latest Insights

API self-service
Blogs

APIs powering self-service

The demystifying and democratisation of innovation by IT leaders will help bolster the self-service of the broader organisation.

Salesforce CRM for the public sector
Blogs

CRM for Citizen Relationship Management

While the times have been changing for a while, current events have accelerated the need for public agencies to adapt to a changing world.

Open banking APIs
Blogs

Open Banking – How APIs are fast-tracking growth

When it comes to reaching market faster and scaling with both speed and stability, APIs have been a crucial component of many Fintechs.