Overview
The WSO2 Micro Integrator module for Ballerina enables integration developers to leverage Ballerina's powerful transformation capabilities within WSO2 MI. Ballerina, being a cloud-native programming language with built-in support for JSON and XML, simplifies data transformations compared to traditional Class Mediators. The module also provides access to Ballerina's extensive ecosystem of language modules and connectors, enhancing connectivity with external systems.
Prerequisites¶
- WSO2 Micro Integrator 4.2.0 or later
- Java Development Kit (Version 17 for MI 4.2.0/4.3.0, Version 21 for MI 4.4.0)
- VS Code with WSO2 Micro Integrator extension installed
- Ballerina 2201.12.0 or later
- Ballerina VS Code extensions installed
- Ballerina Integrator VS Code extensions installed
Get Started with Ballerina Module for MI¶
There are two ways to use the Ballerina module in your WSO2 MI projects:
- Using the WSO2 MI VS Code Extension
- Using the Command Line Interface (CLI)
Method 1: Use WSO2 MI VS Code Extension¶
- Install the WSO2 Micro Integrator VSCode Extension.
- Create a new integration project or open an existing project.
-
Expand the artifact types in the Add artifact view and select Ballerina Module.
-
In the
Create Ballerina Module
form, enter a name and a version for the module and click Create. -
Update the generated sample Ballerina code with your transformation logic and save the file.
-
Click the Build Ballerina Module icon.
Then, there will be a notification in the bottom right corner of the VS Code window indicating that the module is being built.
-
Once the Ballerina module is successfully built, it will appear in the
Mediator palette
, allowing it to be added when constructing integration flows.If any changes are made to the transformation logic, the module can be rebuilt by clicking the Build Ballerina Module icon or by clicking the Refresh icon next to the relevant module in the Mediator Palette.
Method 2: Use Command Line Interface (CLI)¶
Pull mi-module-gen
tool¶
First, you need to pull the mi-module-gen
tool which is used to create the WSO2 MI module.
bal tool pull mi-module-gen
Note: To list-down all the available tools with versions, you can use the command
bal tool list
and to use the specific version of the tool, you can use the commandbal tool use mi-module-gen:<version>
. To remove the tool, you can use the commandbal tool remove mi-module-gen
.
Write Ballerina transformation¶
Create a new Ballerina project using bal new projectName
or use an existing one and write your transformation logic.
Import the module wso2/mi
in your Ballerina program.
import wso2/mi;
Next, you need to write the Ballerina transformation in a Ballerina project. For example,
@mi:Operation {}
public function gpa(xml rawMarks, xml credits) returns xml {
// Your logic to calculate the GPA
}
Ballerina function that contains @mi:Operation
annotation maps with an operation in the Ballerina module.
Generate the module¶
-
Use the
bal mi-module-gen
command to generate the WSO2 Micro Integrator module from Ballerina project.bash bal mi-module-gen -i <path_to_ballerina_project>
-
Above command generates the module zip in the same location. Now, goto the mediator palette and go to the Connection section. Then click on Add connection .
-
Then select the Import Connector option.
-
Select the Upload connector zip file option and select the generated zip file.
That's it! Now you can use the Ballerina module in your WSO2 Micro Integrator project.