Showing posts with label MuleSoft Training. Show all posts
Showing posts with label MuleSoft Training. Show all posts

Wednesday, May 3, 2017

MuleSoft's Scope of Session and Flow Variables

1.0 Overview

We need to know the life of session variables (sessionVars) and flow variables (flowVars) in MuleSoft. If you are like me, aiming to get the "MuleSoft Certified Developer - Integration Professional," the concept of variable scopes needs to be clear in your mind. Some of the questions you might have would be like the following.

1.1 The Question That Tests Our Understanding

Based on Figure 1.0 below, what flow and session variable is accessible in the response scope of "Flow A" and "Flow B?"

2.0 Crystalizing Variable Scope Behaviours

In order to find out, we could create a response scope in both flow A & B, we could modify it to be like Figure 2.0. I have put in 4 logging to print out flow and session variables in both the request and response scope of flow A and B.

I have keyed in the following MEL expressing in the loggers:-
FLOW <A or B> <Request or Response> Scope Accessible Variables: #[flowVars.flowVarriable1] #[sessionVars.SessionVariable1] #[flowVars.flowVarriable2] #[sessionVars.SessionVariable2]

2.1 The sample code to exemplify the behaviors

These loggers will print out the values of the variables in their respective places. The full mule xml code for this running test program is as per the following:-
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:vm="http://www.mulesoft.org/schema/mule/vm" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking"
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/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd">
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration" />
<vm:connector name="VM" validateConnections="true" doc:name="VM" />
<flow name="FlowA">
<http:listener config-ref="HTTP_Listener_Configuration" path="/test" doc:name="HTTP" />
<set-variable variableName="flowVarriable1" value="F1" doc:name="flowVarriable1" />
<set-session-variable variableName="SessionVariable1" value="S1" doc:name="SessionVariable1" />
<logger
message="FLOW A Request Scope Accessible Variables: #[flowVars.flowVarriable1] #[sessionVars.SessionVariable1] #[flowVars.flowVarriable2] #[sessionVars.SessionVariable2]"
level="INFO" doc:name="Logger" />
<vm:outbound-endpoint exchange-pattern="request-response" path="testQ" connector-ref="VM" doc:name="VM" />
<response>
<logger
message="FLOW A Response Scope Accessible Variables: #[flowVars.flowVarriable1] #[sessionVars.SessionVariable1] #[flowVars.flowVarriable2] #[sessionVars.SessionVariable2]"
level="INFO" doc:name="Logger" />
</response>
</flow>
<flow name="FlowB">
<vm:inbound-endpoint exchange-pattern="request-response" path="testQ" connector-ref="VM" doc:name="VM" />
<set-variable variableName="flowVarriable2" value="F2" doc:name="flowVarriable2" />
<set-session-variable variableName="SessionVariable2" value="S2" doc:name="SessionVariable2" />
<logger
message="FLOW B Request Scope Accessible Variables: #[flowVars.flowVarriable1] #[sessionVars.SessionVariable1] #[flowVars.flowVarriable2] #[sessionVars.SessionVariable2]"
level="INFO" doc:name="Logger" />
<response>
<logger
message="FLOW B Response Scope Accessible Variables: #[flowVars.flowVarriable1] #[sessionVars.SessionVariable1] #[flowVars.flowVarriable2] #[sessionVars.SessionVariable2]"
level="INFO" doc:name="Logger" />
</response>
</flow>
</mule>
You can trigger the mule flow via Postman, by pointing to the test uri, when you click send on postman as per Figure 3.0.

2.2 Result of Code Run

If you run the Mule application the following log entries would be printed.
LoggerMessageProcessor: FLOW A Request Scope Accessible Variables: F1 S1 null null
LoggerMessageProcessor: FLOW B Request Scope Accessible Variables: null S1 F2 S2
LoggerMessageProcessor: FLOW B Response Scope Accessible Variables: null S1 F2 S2
LoggerMessageProcessor: FLOW A Response Scope Accessible Variables: F1 S1 null S2

3.0 Conclusion

A graph representation on the accessible variables in each response and request scope are as depicted in the following Figure 4.0.

To simplify this, look at the following depiction (Figure 5.0). Notice the response scope of "Flow A", the S2 variable is accessible by "Flow A" once "Flow B" returns the control to the calling flow.

From this behavior we can conclude that as long as a session variable is created it can traverse transport and be accessible by the calling flow and vice versa. With this new understanding you could answer certification examination questions confidently, because we can’t dispute the results of our test. As always if you want to understand a core concept in Mule or another technology it is always good to devise a lap or a program to test out it's behavior. There is no better substitute to deliberate practice in gaining new experience.

I have included some references URL in this article, you could read up more about Session and Flow variables via those links.

Wednesday, March 15, 2017

MuleSoft Composite Source Scope

This is a lab exercise to create a flow that is able to accept payload from multiple different source end points. It shows how we could use MuleSoft's composite source scope to achieve this.



Link to source code here



Tuesday, January 24, 2017

Mule-soft Champions Web Site

After passing my MuleSoft certified associate certification I was immediately subscribed to the “Champions Programme”. I didn’t know what it was about so I ignored the registration mail and didn’t really pay attention to it for 1 to 2 weeks.

One evening as I open up the mail, I clicked on the link and was brought immediately to the “Champions Website”, before I talk about champions web site, the first time I experience developing integration in MuleSoft is via the first “MuleSoft certified associate” training, and once I have finished the training I am hooked to MuleSoft I want to know more, I want to work on the product, I want to create stuff, roll my sleves up and start building solution, making changes that will help people, businesses and organizations, I find that I need to know more about MuleSoft development.
So as I head into the champions web site I found that Mulesoft have gamified the whole learning continuous community connection and learning process for MuleSoft and I like it.

At the point of this writing generally the web site has 3 navigational section that is worth our attention. They are namely


  1. My Challenges – Where you can choose and pick what challenges you want to take on, and if you successfully complete the challenge, you will then accumulate points, the points that you have accumulated will then allow you to redeem gifts at the reward stores.
  2. Discussions – Is where you can post and view other mulesoft developer’s post on a topic of discussion, you can answer the discussion or ask question about a discussion.
  3. Reward Store- This is the beauty of the whole gamification, here is where you can redeem stuff with the points you have accumulated from winning the challenges.



On the left hand pane of the champions web site you will also see a “Leaderboard” where it shows who is leading in terms of points accumulation.
Its not just all work and no play there are challenges that are fun and has nothing to do with MuleSoft at all, these are the challenges where you can do when you need a break. This whole web site is addictive.

And the most noble thing of all about the champions web site is that it allows the players to get a shot at higher education, it allows the mulesoft development community to persue futher education in development of mulesoft solution.

If you navigate into the rewards section there are many type of rewards, you have the mulesoft t-shirts, the max mule soft toy, the storm trooper helmet and the most Nobel of all the gift is the chance to a higher education, which I am aiming for, as I want to know more about the MuleSoft product.



There are so many strategy to get a complete education into MuleSoft to continue your persuit of mastering the development skills, to accumulate the points you can answer question on stack overflow or speak at a mulesoft event.



Or you could create tutorial videos about mulesoft development.



You could publish a blog about mulesoft , that will get you 1000 points do it 15 times and you will get your education ticket, but what you didn’t realize is tha writing a blog, talking about it and recording videos are chances for you to review and revised what you already know about the product, and it helps you absorb even more knowledge when you go for the actual course.





This is the most brilliant idea to get the MuleSoft development community together, on top of it being a fantastic integration product this Champions website is just here to glue all of use mule devs together to learn, discuss and innovate to make it an even better product.

Its Brilliant !!!!