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

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

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

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

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

Related

  • Why and How To Integrate Elastic APM in Apache JMeter
  • Transitioning From Groovy to Kotlin for Gradle Android Projects
  • Rethinking Enterprise Integration: The Understated Role of Enterprise Service Bus (ESB)
  • Streamlining Your Workflow With the Jenkins HTTP Request Plugin: A Guide to Replacing CURL in Scripts

Trending

  • The Future of Java and AI: Coding in 2025
  • The Role of AI in Identity and Access Management for Organizations
  • Navigating Change Management: A Guide for Engineers
  • Analyzing Techniques to Provision Access via IDAM Models During Emergency and Disaster Response
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. Groovy Component With Mule ESB

Groovy Component With Mule ESB

Learn how the Groovy component is used in Mule flows to integrate custom scripts. This tutorial shows you how to configure and utilize the Groovy component.

By 
Jitendra Bafna user avatar
Jitendra Bafna
DZone Core CORE ·
May. 30, 17 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
21.7K Views

Join the DZone community and get the full member experience.

Join For Free

The Groovy component is very similar to Python, Ruby or Java components. The Groovy component provides developers with the facilities to integrate custom scripts into a flow using the Groovy scripting engine.

As an example, you can write a custom script using Groovy language for an application, save it in a separate file and then configure the Groovy component to reference the file. Or, after placing the Groovy component on the Studio canvas you can type in the script through the Groovy Pattern Properties pane.

Place the Groovy component in the message processor region from the Mule palette.

Image title

Image title

Use the Advanced tab to configure the interceptors and property for the Groovy component.

Interceptors enable the developer to provide additional services to the component, such as the ability to log transactions and the ability to log the time for each transaction.

Configure these parameters to define attribute keys and their associated values. This enables the component to quickly look up a value associated with a key.

Image title

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd">
    <flow name="sdfsffsdFlow">
        <scripting:component doc:name="Groovy">
            <scripting:script engine="Groovy"><![CDATA[a=10
b=20

sum=Integer.parseInt(a)+Integer.parseInt(b)]]></scripting:script>
        </scripting:component>
    </flow>
</mule>

Accessing Flow Variable in the Groovy Component

message.getInvocationProperty('myFlowVariable')

OR

message.getProperty('myFlowVariable',org.mule.api.transport.PropertyScope.INVOCATION)

OR

flowVars['myFlowVariable']

Accessing Session Variable in the Groovy Component

message.getSessionProperty('mySessionVariable')

OR

message.getProperty('mySessionVariable',org.mule.api.transport.PropertyScope.SESSION)

OR

sessionVars['mySessionVariable']

Setting a Property in the Groovy Component

Go to the Advanced tab and add a property.

Image title

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd">
    <flow name="sdfsffsdFlow">
        <scripting:component doc:name="Groovy">
            <scripting:script engine="Groovy">
                <property key="num1" value="#[flowVars.a]"/>
                <property key="num2" value="#[flowVars.b]"/><![CDATA[sum=Integer.parseInt(num1)+Integer.parseInt(num2)]]></scripting:script>
        </scripting:component>
    </flow>
</mule>

Here is the video tutorial:


Now you know how to use the Groovy component with Mule ESB.

Groovy (programming language) Enterprise service bus

Opinions expressed by DZone contributors are their own.

Related

  • Why and How To Integrate Elastic APM in Apache JMeter
  • Transitioning From Groovy to Kotlin for Gradle Android Projects
  • Rethinking Enterprise Integration: The Understated Role of Enterprise Service Bus (ESB)
  • Streamlining Your Workflow With the Jenkins HTTP Request Plugin: A Guide to Replacing CURL in Scripts

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!