Author: Arif Ali Mansuri
In this blog, I will walk you through the process of publishing and implementing the DataWeave Library.
The important question is: Why do we need this?
DataWeave is the only functional programming language that the MuleSoft developer uses for the whole transformation process, making MuleSoft Integration impossible without it. Writing the same piece of code each time as a business requirement when common mapping across multiple layers of API-led connectivity is required is a waste of time and effort. If there is something that addresses this issue, they should keep the common mapping somewhere and provide it to us as needed.
Let’s start the process.
- Anypoint Platform.
- Visual Studio code.
- DataWeave 2.0 (BETA) Extension.
- Anypoint Studio.
- Organization ID – Get it through below simple steps.
- Login to Anypoint Platform.
- Tap on Access Management.
- Click on Business Groups.
- Click the name of your organization & go to Settings.
- Copy Business Group ID this act as Organization ID.
Just follow the below steps:
- Open Visual Studio Code or Download Visual studio code. Link
- Go to Extensions.
- Search for DataWeave & Installed.
- Next, go to view > Command Palette.
- Search for DataWeave: Create New Library Project.
- Create it by passing default configurations.
- Choose a project path.
Now create your desired DataWeave function. Here I am creating a demo function that returns the lowercase of the passed input string.
- You can try the above-created function by using it in any mapping.
- As a source code to build perfect UNIT tests, it is important that you can create test cases for unit testing too.
To deploy the above-created DataWeave Library, make the changes to pom.xml mentioned below.
- Go to the Project path (refer to the last screenshot of Step 2).
- Go to pom.xml and update groupId & enable the distribution management repository tag.
- Add groupId.
- Enable distributionManagement repository.
- Now go to system/users/*/.m2 and update settings.xml
- Add server in setting.xml for the same <id> as mentioned above <distributionManagement> and provide your Anypoint credentials.
- Run the below maven command to Publish.
Now run the mvn deploy command to deploy it on Anypoint exchange.
- DataWeave Library successfully deployed to Anypoint Exchange.
Now it’s time to utilize our deployed DataWeave Library.
- Log In to Anypoint Platform.
- Go to Exchange in root Organization and check on the dropdown for DataWeave Library(BETA).
- Select deployed DataWeave library.
- You can also see the function definition in Exchange.
- Tap on Dependency Snippets > copy it.
<dependency> <groupId>*********************************************</groupId> <artifactId>custom-logics-arif</artifactId> <version>1.0.0</version> <classifier>dw-library</classifier> </dependency>
- Open any Mule Application in Anypoint Studio.
- Paste copied Dependency in pom.xml dependencies.
Now open the drag Transform message from Mule Palette and import the created function by the below script.
- Import demo form MyModule.