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
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

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
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

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Mule Custom Connector Using XML SDK
  • MuleSoft Custom Connector With XML SDK
  • Log Forwarding Connector Mule XML-SDK
  • Make Your Integration Seamless By Using Ballerina Client Connectors

Trending

  • Integration Isn’t a Task — It’s an Architectural Discipline
  • How to Build Real-Time BI Systems: Architecture, Code, and Best Practices
  • Designing a Java Connector for Software Integrations
  • Customer 360: Fraud Detection in Fintech With PySpark and ML
  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.

By 
Guruprasad Malenki user avatar
Guruprasad Malenki
·
Aug. 27, 20 · Analysis
Likes (3)
Comment
Save
Tweet
Share
5.1K 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.

Related

  • Mule Custom Connector Using XML SDK
  • MuleSoft Custom Connector With XML SDK
  • Log Forwarding Connector Mule XML-SDK
  • Make Your Integration Seamless By Using Ballerina Client Connectors

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!