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
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
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
Partner Zones AWS Cloud
by AWS Developer Relations
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
Partner Zones
AWS Cloud
by AWS Developer Relations
Building Scalable Real-Time Apps with AstraDB and Vaadin
Register Now

Trending

  • What Is React? A Complete Guide
  • Why You Should Consider Using React Router V6: An Overview of Changes
  • Introduction To Git
  • Writing a Vector Database in a Week in Rust

Trending

  • What Is React? A Complete Guide
  • Why You Should Consider Using React Router V6: An Overview of Changes
  • Introduction To Git
  • Writing a Vector Database in a Week in Rust
  1. DZone
  2. Coding
  3. Languages
  4. Mule Smart Logging Connector Using XML SDK

Mule Smart Logging Connector Using XML SDK

This document describes demonstrating steps to build a mule soft logging connector using XML SDK instead of java SDK connector.

Guruprasad Malenki user avatar by
Guruprasad Malenki
·
Aug. 27, 20 · Analysis
Like (3)
Save
Tweet
Share
4.28K Views

Join the DZone community and get the full member experience.

Join For Free

Preface

This document describes demonstrating steps to build a mule soft logging connector using XML SDK instead of java SDK connector, which extends mule runtime capabilities.

This approach is easier to build compared to the existing JAVA Mule SDK

SDK in Mule 4

Mule SDK connector enables reusability, offload complexity, and loosely coupled from mule project.

When we develop a Mule connector module using either the Java or XML SDKs, we are developing on top of Mule Extensions API. This API is a well-defined contract for how modules can interact with the Mule Runtime. These SDKs provide a simple layer of abstraction over the Extensions API so developers do not need to have details of how to use the API. The arc-type maven command is responsible to generate this skeleton.

XML SDK Use Case Mule-smart-logging-connector

A most useful  logging connector can be created using XML SDK to fit into any my mule soft project.

Prerequisites:

Java 1.8

Mule Runtime 4.x.x

Any point Studio 7.XX

Step 1: Generation of XML SDK Skeleton

To create the XML SDK template, we should run the following command at any desired location.

Plain Text
 




xxxxxxxxxx
1


 
1
mvn archetype:generate      -DarchetypeGroupId=org.mule.extensions -DarchetypeArtifactId=mule-extensions-xml-archetype   -DgroupId=org.mule.extension      -DartifactId=mule-smart-logging-connector   -DmuleConnectorName=mule-smart-logging-connector       



If the studio is installed with https://repository.mulesoft.org/nexus-ee/content/repositories/releases/archetype-catalog.xml, we can generate this project in the studio as well.

This will generate a skeleton with extension file module-Hello.xml, which is having below structure seen in any point studio 7.4

mule-smart

Step 2: Replace module-hello.xml with module-smart-logging-Connector.xml, with below simple self-explanatory xml code.

XML
 




xxxxxxxxxx
1
40


 
1
<?xml version="1.0" encoding="UTF-8"?>
2
<module name="mule-smart-logging-connector"
3
        prefix="smart-logger"
4
        doc:description="This module relies in runtime provided components"
5
 
6
         xmlns="http://www.mulesoft.org/schema/mule/module"
7
        xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
8
        xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
9
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"      
10
        xmlns:mule="http://www.mulesoft.org/schema/mule/core"    
11
        xmlns:httpn="http://www.mulesoft.org/schema/mule/http"  
12
         xmlns:wsc="http://www.mulesoft.org/schema/mule/wsc"   
13
        xsi:schemaLocation="
14
        http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
15
         http://www.mulesoft.org/schema/mule/module http://www.mulesoft.org/schema/mule/module/current/mule-module.xsd
16
           http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
17
           http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
18
           http://www.mulesoft.org/schema/mule/module http://www.mulesoft.org/schema/mule/module/current/mule-module.xsd
19
           http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
20
   
21
 <property name="AppName" type="string"></property>
22
<property name="ApiVersion" type="string"></property>
23
<property name="MuleEnvironment" type="string"></property>
24
    <operation name="smartlog">
25
        <parameters>
26
            <parameter name="messageid" type="string"/>
27
            <parameter name="transactionid" type="string"/>
28
             <parameter name="event" type="string"/>         
29
        </parameters>      
30
        <body>
31
 <mule:logger category="com.techstar.log" level="INFO" doc:name="Logger" message="#['{'++'"transactionid"'++ ':' ++  '"' ++ vars.transactionid ++'"'++ ',' 
32
 ++ '"messageid"'++':' ++ '"'++ vars.messageid ++ '"'++ ','
33
  ++ '"AppName"'++':' ++ '"'++ vars.AppName ++ '"'++ ','
34
   ++ '"ApiVersion"'++':' ++ '"'++ vars.ApiVersion ++ '"'++ ','
35
      ++ '"MuleEnv"'++':' ++ '"'++ vars.MuleEnvironment ++ '"'++ ','     
36
  ++ '"logevent"'++':' ++ '"'++ vars.event ++ '"'++ '}']"></mule:logger> 
37
        </body>
38
    </operation>
39
 </module>
40

          



Here I am declaring three input parameters message-id, transaction-id and event, and 3 configuration property parameter AppName, API version, and MuleEnv as part of my smart logger required parameter.

Finally, log all the above parameters under a package or category com.techstar.log by concatenating all the above parameters.

Step 3: To resolve a few dependencies like a mule:log etc, it may require to update or add maven plugin latest version in the pom file.

XML
 




xxxxxxxxxx
1


 
1
<groupId>org.apache.maven.plugins</groupId>
2
 <artifactId>maven-resources-plugin</artifactId>
3
 <version>${maven.resources.plugin.version}</version>



Step 4: Install the connector using simple maven command 

XML
 




xxxxxxxxxx
1


 
1
mvn clean install -DskipTests



This step will install the smart connector in local maven repository


Step 5:- Add this dependency in any project pom file

XML
 




xxxxxxxxxx
1


 
1
     <dependency>
2
            <groupId>org.mule.extension</groupId>
3
            <artifactId>mule-smart-logging-connector</artifactId>
4
            <version>1.0.1</version>
5
            <classifier>mule-plugin</classifier>
6
        </dependency>
7

          



Step 6:- complete the configuration for the smart connector in the project, which looks likes below

mule-test

mule-smart

Step 7: Once it runs in the studio, the console logs looks like below

Plain Text
 




xxxxxxxxxx
1


 
1
INFO  2020-08-20 21:32:19,862 [[MuleRuntime].uber.03: [mule-test-app].mule-test-appFlow.CPU_LITE @1a4a6d9e] [processor: smartlog/processors/0; event: 86842840-e2fe-11ea-aa04-4c1d96260e7b] com.techstar.log: {"transactionid":"814cf14a-1c54-4257-bc26-a2de7f195bf3","messageid":"0bcb76cb-a99d-4107-8423-ca1369ed75d7","AppName":"mule-test-app","ApiVersion":"v1.0","MuleEnv":"Dev","logevent":"Entering Main FLow"}



Step 8: Once it deployed in the cloud, the runtime logs look like below

runtime log

Limitations:

The community edition having limited functionality available for development.

Final Conclusion

The Mule SDK allows MuleSoft developers to extend the Mule runtime with good features. This is made up of Java SDK, and the XML SDK. XML SDK is easier to develop without using any java code in the mule. 

Before we start developing a Mule module, we should decide which SDK and which version we are going to use, etc.

The decisions we make will depend on your particular project requirement.

References

  • Creating XML SDK
  • Mule XML SDK Repository

Hope this will be useful.

Software development kit XML Connector (mathematics)

Opinions expressed by DZone contributors are their own.

Trending

  • What Is React? A Complete Guide
  • Why You Should Consider Using React Router V6: An Overview of Changes
  • Introduction To Git
  • Writing a Vector Database in a Week in Rust

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: