SlideShare a Scribd company logo
1 of 14
By Anirban Sen Chowdhary
We have often seen that people asking how the variables can be accessed in Groovy Script or
Java..
Well, accessing variables in Groovy Script or Java are almost in same way and we will see a
simple demo of doing it.
But before we start, we will be seeing what are the variables we have in Mule…
Mule basically have 2 types of variables:-
• Flow variables :- Flow variables are the variables in Mule whose scope is limited to a flow
or a sub flow and whose values doesn’t cross outside a flow level.
• Session variables :- Session variables are basically global variable in that application and
it’s scope is all over the flow declared or designed in the application. Session variables
can be declared in any flow and can be accessed from any other flow or sub flow
Now, let’s see how can we access a Session variable and a Flow variable from a Groovy
script..
Let’s consider we have defined a Session variable and a Flow variable in our flow as follow
:-
<set-variable variableName="myflowVariable" value="TestFlowVariable" doc:name="Variable"/>
<set-session-variable variableName="mysessionVariable" value="TestSessionVariable"
doc:name="Session Variable"/>
Now, we will see how to retrieve these values in Groovy script
Now, we can use the following to retrieve a Flow variables in a Groovy script :-
message.getInvocationProperty('myflowVariable')
Or
message.getProperty("myflowVariable", org.mule.api.transport.PropertyScope.INVOCATION)
Or simply
flowVars['myflowVariable']
Any of the above code will retrieve the value of Flow variables in Groovy
Similarly we can use the following to retrieve a Session variable in a Groovy script :-
message.getSessionProperty('mysessionVariable')
Or
message.getProperty(" 'mysessionVariable ", org.mule.api.transport.PropertyScope.SESSION)
Or simply
sessionVars['mysessionVariable ']
Any of the above code will retrieve the value of Session variables in Groovy
So, let’s test our application… our Mule flow will be as follows :-
You can see we are setting the variables in the flow and we will be retrieving the values in
the Groovy scripts and print it in logger
So, if we test the application we will get the Session variable and Flow variables values in
console as follows :-
So we are getting the values of the Session variable and Flow variables with all the method
we have used in Groovy
We can use the same methods in our Java class to retrieve the values of variables
So, now we will look to set variables from Groovy script and access it in flow :-
You can set the Flow variables in Groovy using the following syntax :-
message.setProperty('key', 'value', org.mule.api.transport.PropertyScope.INVOCATION);
or
message.setInvocationProperty('key','value');
And you can set the Session variables in Groovy using the following syntax :-
message.setProperty('key', 'value', org.mule.api.transport.PropertyScope.SESSION);
or
message.setSessionProperty('key','value');
Now, lets design our flow again and this time we will be setting the variables in Groovy and
access it in flow using loggers. You can easily see we are setting the variables (both Session
variable and Flow variable) in 2 different ways for each variable. You can use any one
method out of 2
In logger we can see the values of the variables
So, this is the way you can read as well as set variables (both Session variable and Flow
variable) in Groovy or Java
In my next slide I will bring some other techniques in Mule
implementation .
Hope you have enjoyed this simpler version.
Keep sharing your knowledge and let our Mule community grow 
Accessing Mule variables in groovy

More Related Content

What's hot

Design Pattern - MVC, MVP and MVVM
Design Pattern - MVC, MVP and MVVMDesign Pattern - MVC, MVP and MVVM
Design Pattern - MVC, MVP and MVVMMudasir Qazi
 
Automation of Release and Deployment Management - Maveric
Automation of Release and Deployment Management - MavericAutomation of Release and Deployment Management - Maveric
Automation of Release and Deployment Management - MavericMaveric Systems
 
What-is-Laravel-23-August-2017.pptx
What-is-Laravel-23-August-2017.pptxWhat-is-Laravel-23-August-2017.pptx
What-is-Laravel-23-August-2017.pptxAbhijeetKumar456867
 
Mulesoft Anypoint platform introduction
Mulesoft Anypoint platform introductionMulesoft Anypoint platform introduction
Mulesoft Anypoint platform introductiongijish
 
MVVM in iOS presentation
MVVM in iOS presentationMVVM in iOS presentation
MVVM in iOS presentationG ABHISEK
 
Best Practices for API Security
Best Practices for API SecurityBest Practices for API Security
Best Practices for API SecurityMuleSoft
 
An Introduction to Maven
An Introduction to MavenAn Introduction to Maven
An Introduction to MavenVadym Lotar
 
Containerizing MuleSoft applications for hybrid deployment
Containerizing MuleSoft applications for hybrid deployment Containerizing MuleSoft applications for hybrid deployment
Containerizing MuleSoft applications for hybrid deployment JuliaDemidova3
 
Microservices with Spring Boot Tutorial | Edureka
Microservices with Spring Boot Tutorial | EdurekaMicroservices with Spring Boot Tutorial | Edureka
Microservices with Spring Boot Tutorial | EdurekaEdureka!
 
Microservice Architecture using Spring Boot with React & Redux
Microservice Architecture using Spring Boot with React & ReduxMicroservice Architecture using Spring Boot with React & Redux
Microservice Architecture using Spring Boot with React & ReduxNexThoughts Technologies
 
Virtual Meetup - MuleSoft Catalyst and Accelerator for Banking
Virtual Meetup - MuleSoft Catalyst and Accelerator for BankingVirtual Meetup - MuleSoft Catalyst and Accelerator for Banking
Virtual Meetup - MuleSoft Catalyst and Accelerator for BankingJimmy Attia
 
GoF Design patterns I: Introduction + Structural Patterns
GoF Design patterns I:   Introduction + Structural PatternsGoF Design patterns I:   Introduction + Structural Patterns
GoF Design patterns I: Introduction + Structural PatternsSameh Deabes
 

What's hot (20)

Design Pattern - MVC, MVP and MVVM
Design Pattern - MVC, MVP and MVVMDesign Pattern - MVC, MVP and MVVM
Design Pattern - MVC, MVP and MVVM
 
Automation of Release and Deployment Management - Maveric
Automation of Release and Deployment Management - MavericAutomation of Release and Deployment Management - Maveric
Automation of Release and Deployment Management - Maveric
 
Apache maven 2 overview
Apache maven 2 overviewApache maven 2 overview
Apache maven 2 overview
 
What-is-Laravel-23-August-2017.pptx
What-is-Laravel-23-August-2017.pptxWhat-is-Laravel-23-August-2017.pptx
What-is-Laravel-23-August-2017.pptx
 
Mvc, mvp, mvvm...
Mvc, mvp, mvvm...Mvc, mvp, mvvm...
Mvc, mvp, mvvm...
 
Mulesoft Anypoint platform introduction
Mulesoft Anypoint platform introductionMulesoft Anypoint platform introduction
Mulesoft Anypoint platform introduction
 
MVVM in iOS presentation
MVVM in iOS presentationMVVM in iOS presentation
MVVM in iOS presentation
 
Best Practices for API Security
Best Practices for API SecurityBest Practices for API Security
Best Practices for API Security
 
Cloudhub and Mule
Cloudhub and MuleCloudhub and Mule
Cloudhub and Mule
 
Laravel
LaravelLaravel
Laravel
 
An Introduction to Maven
An Introduction to MavenAn Introduction to Maven
An Introduction to Maven
 
Maven ppt
Maven pptMaven ppt
Maven ppt
 
Containerizing MuleSoft applications for hybrid deployment
Containerizing MuleSoft applications for hybrid deployment Containerizing MuleSoft applications for hybrid deployment
Containerizing MuleSoft applications for hybrid deployment
 
Microservices with Spring Boot Tutorial | Edureka
Microservices with Spring Boot Tutorial | EdurekaMicroservices with Spring Boot Tutorial | Edureka
Microservices with Spring Boot Tutorial | Edureka
 
Laravel overview
Laravel overviewLaravel overview
Laravel overview
 
Introduction of sdlc
Introduction of sdlcIntroduction of sdlc
Introduction of sdlc
 
Microservice Architecture using Spring Boot with React & Redux
Microservice Architecture using Spring Boot with React & ReduxMicroservice Architecture using Spring Boot with React & Redux
Microservice Architecture using Spring Boot with React & Redux
 
Spring boot
Spring bootSpring boot
Spring boot
 
Virtual Meetup - MuleSoft Catalyst and Accelerator for Banking
Virtual Meetup - MuleSoft Catalyst and Accelerator for BankingVirtual Meetup - MuleSoft Catalyst and Accelerator for Banking
Virtual Meetup - MuleSoft Catalyst and Accelerator for Banking
 
GoF Design patterns I: Introduction + Structural Patterns
GoF Design patterns I:   Introduction + Structural PatternsGoF Design patterns I:   Introduction + Structural Patterns
GoF Design patterns I: Introduction + Structural Patterns
 

Viewers also liked

Calling database with groovy in mule
Calling database with groovy in muleCalling database with groovy in mule
Calling database with groovy in muleAnirban Sen Chowdhary
 
Using groovy component
Using groovy componentUsing groovy component
Using groovy componentRahul Kumar
 
Calling flow from another application
Calling flow from another applicationCalling flow from another application
Calling flow from another applicationAnirban Sen Chowdhary
 
Calling flow from another application 2
Calling flow from another application 2Calling flow from another application 2
Calling flow from another application 2Anirban Sen Chowdhary
 
Mule JMS Transport
Mule JMS TransportMule JMS Transport
Mule JMS TransportRupesh Sinha
 
Until successful component in mule demo
Until successful component in mule demoUntil successful component in mule demo
Until successful component in mule demoSudha Ch
 
Basic example using message properties component
Basic example using message properties componentBasic example using message properties component
Basic example using message properties componentprudhvivreddy
 

Viewers also liked (20)

Simple groovy example in mule
Simple groovy example in muleSimple groovy example in mule
Simple groovy example in mule
 
Mule with composite source
Mule with composite sourceMule with composite source
Mule with composite source
 
Mule property placeholder
Mule property placeholderMule property placeholder
Mule property placeholder
 
VM example in mule
VM example in muleVM example in mule
VM example in mule
 
Accessing jms in mule using groovy
Accessing jms in mule using groovyAccessing jms in mule using groovy
Accessing jms in mule using groovy
 
Cloudhub in action
Cloudhub in actionCloudhub in action
Cloudhub in action
 
RAMLing around with mule part2
RAMLing around with mule part2RAMLing around with mule part2
RAMLing around with mule part2
 
Idempotent filter with simple file
Idempotent filter with simple fileIdempotent filter with simple file
Idempotent filter with simple file
 
Calling database with groovy in mule
Calling database with groovy in muleCalling database with groovy in mule
Calling database with groovy in mule
 
Mule MMC as a service
Mule MMC as a serviceMule MMC as a service
Mule MMC as a service
 
Using groovy component
Using groovy componentUsing groovy component
Using groovy component
 
Calling flow from another application
Calling flow from another applicationCalling flow from another application
Calling flow from another application
 
Process file one after another
Process file one after anotherProcess file one after another
Process file one after another
 
Calling flow from another application 2
Calling flow from another application 2Calling flow from another application 2
Calling flow from another application 2
 
Xml to xml transformation in mule
Xml to xml transformation in muleXml to xml transformation in mule
Xml to xml transformation in mule
 
Mule message enricher
Mule message enricherMule message enricher
Mule message enricher
 
Mule JMS Transport
Mule JMS TransportMule JMS Transport
Mule JMS Transport
 
Until successful component in mule demo
Until successful component in mule demoUntil successful component in mule demo
Until successful component in mule demo
 
Basic example using message properties component
Basic example using message properties componentBasic example using message properties component
Basic example using message properties component
 
Accessing jms in mule using groovy
Accessing jms in mule using groovyAccessing jms in mule using groovy
Accessing jms in mule using groovy
 

Similar to Accessing Mule variables in groovy

Cache for community edition
Cache for community editionCache for community edition
Cache for community editionMohammed246
 
Cache for community edition
Cache for community edition Cache for community edition
Cache for community edition javeed_mhd
 
Cache for community edition
Cache for community editionCache for community edition
Cache for community editionF K
 
Cache community edition
Cache community edition Cache community edition
Cache community edition AbdulImrankhan7
 
Cache for community edition
Cache for community edition Cache for community edition
Cache for community edition mdfkhan625
 
Cache for community edition
Cache for community edition Cache for community edition
Cache for community edition Khasim Saheb
 
Cache for community edition
Cache for community editionCache for community edition
Cache for community editionirfan1008
 
Cache for community edition
Cache for community editionCache for community edition
Cache for community editionHasan Syed
 
Cache for community edition
Cache for community editionCache for community edition
Cache for community editionSunil Komarapu
 
Simple groovy example in mule
Simple groovy example in mule Simple groovy example in mule
Simple groovy example in mule Rajkattamuri
 
Groovy example in mule
Groovy example in mule Groovy example in mule
Groovy example in mule mdfkhan625
 
Simple groovy example in mule
Simple groovy example in muleSimple groovy example in mule
Simple groovy example in muleAbdulImrankhan7
 
Simple groovy example in mule
Simple groovy example in muleSimple groovy example in mule
Simple groovy example in mulejaveed_mhd
 
Simple groovy example in mule
Simple groovy example in mule Simple groovy example in mule
Simple groovy example in mule Mohammed625
 
Simple groovy example in mule
Simple groovy example in muleSimple groovy example in mule
Simple groovy example in muleKhan625
 

Similar to Accessing Mule variables in groovy (20)

Map in Mule
Map in MuleMap in Mule
Map in Mule
 
Cache for community edition
Cache for community editionCache for community edition
Cache for community edition
 
Cache for community edition
Cache for community edition Cache for community edition
Cache for community edition
 
Community edition Cache
Community edition CacheCommunity edition Cache
Community edition Cache
 
Cache for community edition
Cache for community editionCache for community edition
Cache for community edition
 
Cache community edition
Cache community edition Cache community edition
Cache community edition
 
Cache for community edition
Cache for community edition Cache for community edition
Cache for community edition
 
Cache for community edition
Cache for community edition Cache for community edition
Cache for community edition
 
Cache for community edition
Cache for community editionCache for community edition
Cache for community edition
 
Cache for community edition
Cache for community editionCache for community edition
Cache for community edition
 
Cache for community edition
Cache for community editionCache for community edition
Cache for community edition
 
Cache for community edition
Cache for community editionCache for community edition
Cache for community edition
 
SmpleGroovyexampleinmule
SmpleGroovyexampleinmuleSmpleGroovyexampleinmule
SmpleGroovyexampleinmule
 
Simple groovy example in mule
Simple groovy example in mule Simple groovy example in mule
Simple groovy example in mule
 
Groovy example in mule
Groovy example in mule Groovy example in mule
Groovy example in mule
 
Simple groovy example in mule
Simple groovy example in muleSimple groovy example in mule
Simple groovy example in mule
 
Groovy in Mule
Groovy in MuleGroovy in Mule
Groovy in Mule
 
Simple groovy example in mule
Simple groovy example in muleSimple groovy example in mule
Simple groovy example in mule
 
Simple groovy example in mule
Simple groovy example in mule Simple groovy example in mule
Simple groovy example in mule
 
Simple groovy example in mule
Simple groovy example in muleSimple groovy example in mule
Simple groovy example in mule
 

More from Anirban Sen Chowdhary

Overview in ringcentral digital line
Overview in ringcentral digital lineOverview in ringcentral digital line
Overview in ringcentral digital lineAnirban Sen Chowdhary
 
RingCentral application development overview
RingCentral application development overviewRingCentral application development overview
RingCentral application development overviewAnirban Sen Chowdhary
 
Overview on ring central errors part 4
Overview on ring central errors part 4Overview on ring central errors part 4
Overview on ring central errors part 4Anirban Sen Chowdhary
 
Setting up your ring central sandbox in steps
Setting up your ring central sandbox in stepsSetting up your ring central sandbox in steps
Setting up your ring central sandbox in stepsAnirban Sen Chowdhary
 
Overview on ring central errors: part 2
Overview on ring central errors: part 2Overview on ring central errors: part 2
Overview on ring central errors: part 2Anirban Sen Chowdhary
 
Call recording overview ring central
Call recording overview  ring centralCall recording overview  ring central
Call recording overview ring centralAnirban Sen Chowdhary
 
Ring central engaging with amazon alexa
Ring central engaging with amazon alexaRing central engaging with amazon alexa
Ring central engaging with amazon alexaAnirban Sen Chowdhary
 
How ring central sdk changing the game
How ring central sdk changing the gameHow ring central sdk changing the game
How ring central sdk changing the gameAnirban Sen Chowdhary
 
When ring central connect salesforce
When ring central connect salesforceWhen ring central connect salesforce
When ring central connect salesforceAnirban Sen Chowdhary
 
Ring central connecting salesforce overview
Ring central connecting salesforce overviewRing central connecting salesforce overview
Ring central connecting salesforce overviewAnirban Sen Chowdhary
 
Ring central call logs overview (part 2)
Ring central call logs overview (part 2)Ring central call logs overview (part 2)
Ring central call logs overview (part 2)Anirban Sen Chowdhary
 

More from Anirban Sen Chowdhary (20)

Change the game with Game changer
Change the game with Game changerChange the game with Game changer
Change the game with Game changer
 
Ring central desktop app overview
Ring central desktop app overviewRing central desktop app overview
Ring central desktop app overview
 
Overview in ringcentral digital line
Overview in ringcentral digital lineOverview in ringcentral digital line
Overview in ringcentral digital line
 
Some basics with ring central
Some basics with ring centralSome basics with ring central
Some basics with ring central
 
Ring central and python
Ring central and pythonRing central and python
Ring central and python
 
RingCentral application development overview
RingCentral application development overviewRingCentral application development overview
RingCentral application development overview
 
Cloze connect ringcentral
Cloze connect ringcentralCloze connect ringcentral
Cloze connect ringcentral
 
Overview on ring central errors part 4
Overview on ring central errors part 4Overview on ring central errors part 4
Overview on ring central errors part 4
 
Setting up your ring central sandbox in steps
Setting up your ring central sandbox in stepsSetting up your ring central sandbox in steps
Setting up your ring central sandbox in steps
 
Overview on ring central errors: part 2
Overview on ring central errors: part 2Overview on ring central errors: part 2
Overview on ring central errors: part 2
 
Overview on ring central errors
Overview on ring central errorsOverview on ring central errors
Overview on ring central errors
 
Call recording overview ring central
Call recording overview  ring centralCall recording overview  ring central
Call recording overview ring central
 
Ring central engaging with amazon alexa
Ring central engaging with amazon alexaRing central engaging with amazon alexa
Ring central engaging with amazon alexa
 
How ring central sdk changing the game
How ring central sdk changing the gameHow ring central sdk changing the game
How ring central sdk changing the game
 
When ring central connect salesforce
When ring central connect salesforceWhen ring central connect salesforce
When ring central connect salesforce
 
Mule 4 connecting ring central
Mule 4 connecting ring centralMule 4 connecting ring central
Mule 4 connecting ring central
 
Ring central sdk
Ring central sdkRing central sdk
Ring central sdk
 
Ring central with okta
Ring central with oktaRing central with okta
Ring central with okta
 
Ring central connecting salesforce overview
Ring central connecting salesforce overviewRing central connecting salesforce overview
Ring central connecting salesforce overview
 
Ring central call logs overview (part 2)
Ring central call logs overview (part 2)Ring central call logs overview (part 2)
Ring central call logs overview (part 2)
 

Recently uploaded

Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 

Recently uploaded (20)

Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 

Accessing Mule variables in groovy

  • 1. By Anirban Sen Chowdhary
  • 2. We have often seen that people asking how the variables can be accessed in Groovy Script or Java.. Well, accessing variables in Groovy Script or Java are almost in same way and we will see a simple demo of doing it.
  • 3. But before we start, we will be seeing what are the variables we have in Mule… Mule basically have 2 types of variables:- • Flow variables :- Flow variables are the variables in Mule whose scope is limited to a flow or a sub flow and whose values doesn’t cross outside a flow level. • Session variables :- Session variables are basically global variable in that application and it’s scope is all over the flow declared or designed in the application. Session variables can be declared in any flow and can be accessed from any other flow or sub flow
  • 4. Now, let’s see how can we access a Session variable and a Flow variable from a Groovy script.. Let’s consider we have defined a Session variable and a Flow variable in our flow as follow :- <set-variable variableName="myflowVariable" value="TestFlowVariable" doc:name="Variable"/> <set-session-variable variableName="mysessionVariable" value="TestSessionVariable" doc:name="Session Variable"/> Now, we will see how to retrieve these values in Groovy script
  • 5. Now, we can use the following to retrieve a Flow variables in a Groovy script :- message.getInvocationProperty('myflowVariable') Or message.getProperty("myflowVariable", org.mule.api.transport.PropertyScope.INVOCATION) Or simply flowVars['myflowVariable'] Any of the above code will retrieve the value of Flow variables in Groovy
  • 6. Similarly we can use the following to retrieve a Session variable in a Groovy script :- message.getSessionProperty('mysessionVariable') Or message.getProperty(" 'mysessionVariable ", org.mule.api.transport.PropertyScope.SESSION) Or simply sessionVars['mysessionVariable '] Any of the above code will retrieve the value of Session variables in Groovy
  • 7. So, let’s test our application… our Mule flow will be as follows :- You can see we are setting the variables in the flow and we will be retrieving the values in the Groovy scripts and print it in logger
  • 8. So, if we test the application we will get the Session variable and Flow variables values in console as follows :- So we are getting the values of the Session variable and Flow variables with all the method we have used in Groovy We can use the same methods in our Java class to retrieve the values of variables
  • 9. So, now we will look to set variables from Groovy script and access it in flow :- You can set the Flow variables in Groovy using the following syntax :- message.setProperty('key', 'value', org.mule.api.transport.PropertyScope.INVOCATION); or message.setInvocationProperty('key','value');
  • 10. And you can set the Session variables in Groovy using the following syntax :- message.setProperty('key', 'value', org.mule.api.transport.PropertyScope.SESSION); or message.setSessionProperty('key','value');
  • 11. Now, lets design our flow again and this time we will be setting the variables in Groovy and access it in flow using loggers. You can easily see we are setting the variables (both Session variable and Flow variable) in 2 different ways for each variable. You can use any one method out of 2
  • 12. In logger we can see the values of the variables So, this is the way you can read as well as set variables (both Session variable and Flow variable) in Groovy or Java
  • 13. In my next slide I will bring some other techniques in Mule implementation . Hope you have enjoyed this simpler version. Keep sharing your knowledge and let our Mule community grow 