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 Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Mule Custom Connector Using XML SDK
  • Make Your Integration Seamless By Using Ballerina Client Connectors
  • MuleSoft Integration With RabbitMQ
  • Beyond n8n for Workflow Automation: Agent Graphs as Your Universal Agent Harness

Trending

  • Liquibase: Database Change Management and Automated Deployments
  • What Is Plagiarism? How to Avoid It and Cite Sources
  • How AI Is Transforming Software Engineering and How Developers Can Take Advantage
  • How to Format Articles for DZone
  1. DZone
  2. Coding
  3. Languages
  4. Log Forwarding Connector Mule XML-SDK

Log Forwarding Connector Mule XML-SDK

This document describes demonstrating steps to build a muleSoft logging connector using XML SDK instead of Java SDK.

By 
Guruprasad Malenki user avatar
Guruprasad Malenki
·
Aug. 31, 20 · Analysis
Likes (2)
Comment
Save
Tweet
Share
7.2K Views

Join the DZone community and get the full member experience.

Join For Free

Preface

This document describes demonstrating steps to build a muleSoft logging connector using XML SDK instead of Java SDK, to forward the logs into Splunk, ELK, or any other log collector API to store and manage the logs into a centralized location. Similar to Java SDK XML SDK also extends mule runtime capabilities.

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

SDK in Mule 4

https://dzone.com/articles/mule-smart-logging-connector-using-xml-sdk

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
 




x


 
1
mvn archetype:generate  -DarchetypeGroupId=org.mule.extensions   -DarchetypeArtifactId=mule-extensions-xml-archetype   -DarchetypeVersion=1.2.0   -DgroupId=org.mule.extension     -DartifactId= mule-smart-logger-DmuleConnectorName=mule-smart-logger



Step 2: Replace Module-Hello.XML With Module-Smart-Log-Forwarder.XML, With Below Simple Self-Explanatory XML Code

XML
 




xxxxxxxxxx
1
74


 
1
<?xml version="1.0" encoding="UTF-8"?>
2
<module name="Mule-Smart-Log-Connector"
3
        prefix="Log-Forword"
4
        doc:description="This module relies in runtime provided components"
5
         xmlns:http="http://www.mulesoft.org/schema/mule/http"
6
        xmlns="http://www.mulesoft.org/schema/mule/module"
7
        xmlns:mule="http://www.mulesoft.org/schema/mule/core"
8
        xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
9
        xmlns:tns="http://www.mulesoft.org/schema/mule/Log-Forword"
10
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
11
        xsi:schemaLocation="
12
         http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
13
          http://www.mulesoft.org/schema/mule/module http://www.mulesoft.org/schema/mule/module/current/mule-module.xsd
14
           http://www.mulesoft.org/schema/mule/module http://www.mulesoft.org/schema/mule/module/current/mule-module.xsd
15
           http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
16
           http://www.mulesoft.org/schema/mule/Log-Forword http://www.mulesoft.org/schema/mule/Log-Forword/current/mule-module-hello.xsd">
17

          
18
<property name="AppName" type="string"/>
19
<property name="ApiVersion" type="string"/>
20
<property name="MuleEnvironment" type="string"/>
21

          
22
    <http:request-config name="httpreq-config" basePath="/">
23
        <http:request-connection protocol="HTTP" host="log-collectror-app.us-e2.cloudhub.io" />
24
    </http:request-config>
25

          
26
    <operation name="Log-Info">
27
        <parameters>
28
            <parameter name="messageid" type="string"/>
29
            <parameter name="transactionid" type="string"/>
30
            <parameter name="message" type="string"/>
31
        </parameters>
32
        <body>
33
       <mule:async doc:name="Async" >
34
       
35
       <mule:set-variable value="#['{' ++ '&quot;info&quot;' ++ ':'++
36
 '{'++'&quot;transactionid&quot;'++ ':' ++  '&quot;' ++ vars.transactionid ++'&quot;'++ ',' 
37
 ++ '&quot;messageid&quot;'++':' ++ '&quot;'++ vars.messageid ++ '&quot;'++ ','
38
  ++ '&quot;AppName&quot;'++':' ++ '&quot;'++ vars.AppName ++ '&quot;'++ ','
39
   ++ '&quot;ApiVersion&quot;'++':' ++ '&quot;'++ vars.ApiVersion ++ '&quot;'++ ','
40
      ++ '&quot;MuleEnv&quot;'++':' ++ '&quot;'++ vars.MuleEnvironment ++ '&quot;'++ ','     
41
  ++ '&quot;logMessage&quot;'++':' ++ '&quot;'++ vars.message ++ '&quot;'++ '}'++'}']"
42
 doc:name="SetVariable" variableName="logdata" mimeType="application/json"/>
43
  <mule:logger category="com.techstar.log" level="INFO" doc:name="Logger" message="#[vars.logdata]" /> 
44
                <mule:set-payload value="#[vars.logdata]" doc:name="SetPayload" mimeType="application/json"/>
45
           
46
            <http:request config-ref="httpreq-config" path="/info" method="POST" />
47
       </mule:async>
48
        </body>
49
    </operation>
50
    
51
     <operation name="Log-Error">
52
        <parameters>
53
            <parameter name="messageid" type="string"/>
54
            <parameter name="transactionid" type="string"/>
55
             <parameter name="message" type="string"/>
56
        </parameters>
57
        <body>
58
       <mule:async doc:name="Async" >
59
       <mule:set-variable value="#['{' ++ '&quot;error&quot;' ++ ':'++
60
 '{'++'&quot;transactionid&quot;'++ ':' ++  '&quot;' ++ vars.transactionid ++'&quot;'++ ',' 
61
 ++ '&quot;messageid&quot;'++':' ++ '&quot;'++ vars.messageid ++ '&quot;'++ ','
62
  ++ '&quot;AppName&quot;'++':' ++ '&quot;'++ vars.AppName ++ '&quot;'++ ','
63
   ++ '&quot;ApiVersion&quot;'++':' ++ '&quot;'++ vars.ApiVersion ++ '&quot;'++ ','
64
      ++ '&quot;MuleEnv&quot;'++':' ++ '&quot;'++ vars.MuleEnvironment ++ '&quot;'++ ','     
65
  ++ '&quot;logMessage&quot;'++':' ++ '&quot;'++ vars.message ++ '&quot;'++ '}'++'}' ]"
66
 doc:name="SetVariable" variableName="logdata" mimeType="application/json"/>
67
  <mule:logger category="com.techstar.log" level="ERROR" doc:name="Logger" message="#[vars.logdata]"/> 
68
            <mule:set-payload value="#[vars.logdata]" doc:name="SetPayload" mimeType="application/json"/>
69
            <http:request config-ref="httpreq-config" path="/error" method="POST"  />
70
       </mule:async>
71
        </body>
72
    </operation>
73
 </module>
74

          



Step 3: Replace Module-Hello.Xml With Module-Smart-Log-Forwarder.Xml, With Below Simple Self-Explanatory Xml Code

module-hello

Step 4: Add This Dependency in Any Project POM File

XML
 




xxxxxxxxxx
1


 
1
    <dependency>
2
       <groupId>org.mule.extension</groupId>
3
       <artifactId>mule-smart-logger</artifactId>
4
       <version>1.0.17-SNAPSHOT</version>
5
       <classifier>mule-plugin</classifier>
6
</dependency>



Step 5: Configurations

mule-test

mule_smart_log

connector config

Info Log 

INFO  2020-08-23 07:45:45,881 [[MuleRuntime].uber.08: [mule-test-app].log-info/processors/0 @187752a6] [processor: log-info/processors/0/processors/1; event: 8da2f720-e4e6-11ea-a1c7-4c1d96260e7b] com.techstar.log: {"info":{"transactionid":"d839e2e3-65d0-4bfe-8403-466fb22d1cf4","messageid":"cc517773-e99a-41a7-88ac-0448f987af7e","AppName":"mule-test-app-guru","ApiVersion":"v1.0","MuleEnv":"Dev","logMessage":"Entering Main Flow"}}

Error Log

ERROR 2020-08-23 07:45:45,917 [[MuleRuntime].uber.05: [mule-test-app].log-error/processors/0 @3c1f5d7] [processor: log-error/processors/0/processors/1; event: 8da2f720-e4e6-11ea-a1c7-4c1d96260e7b] com.techstar.log: {"error":{"transactionid":"d839e2e3-65d0-4bfe-8403-466fb22d1cf4","messageid":"cc517773-e99a-41a7-88ac-0448f987af7e","AppName":"mule-test-app-guru","ApiVersion":"v1.0","MuleEnv":"Dev","logMessage":"At Error handler"}}

Anypoint Cloud Hub Logs

cloud hub logsAt the Log Collector App

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 made up of Java SDK, and the XML SDK. XML SDK is easier to develop without using any java code in the mule. 

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

Hope this will be useful!

Software development kit Connector (mathematics) XML

Opinions expressed by DZone contributors are their own.

Related

  • Mule Custom Connector Using XML SDK
  • Make Your Integration Seamless By Using Ballerina Client Connectors
  • MuleSoft Integration With RabbitMQ
  • Beyond n8n for Workflow Automation: Agent Graphs as Your Universal Agent Harness

Partner Resources

×

Comments

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

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

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 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook