Wednesday, February 8, 2017

About MuleSoft Session Variables

I have attended the MuleSoft training, and in the training it touched on Session Variables, the training touched the topic of different variables, I understand it but I want to internalize the concepts, so I have created lab experiment about it and have written the results of my findings in Code Project blog.
 MuleSoft Variables Exemplified
The MuleSoft documentation is a rich source of information but there is a gap in articulating the behavior of session variables. As developers we understand that session variable is capable of crossing transport but that notion is not true, as per my documented experiment in code project.

In that experiment I found out that session variables only crosses VM transport but not HTTP transport, to understand this I went back to basics, but reading up what session means in the context of computer science. I got an understanding that the Session mechanism can be implemented in any stack of the OSI communications model (show in the diagram below)
 OSI Communication Model

Some communication model supports session variable crossing transports, where as some don't. HTTP protocol sits in Layer 7 of the OSI model

I also got an understanding that in HTTP Sessions, only the server holds session data (which is stored in session variables). 
In my experiment when I create a mule flow1 to call another mule flow2 via HTTP endpoint. Now physically both flow1 and flow2 sit in the same mule application, but logically flow1 and flow 2 are essentially treated as different host servers.

If you create a session variable in flow1 and calls flow2 via HTTP endpoint the logical thing to expect the session variable of flow1 will not be accessible by flow2, because logically they are treated as different servers (during run time).
The illustration above will show what you will see logically in your mind, it is as if there are two hows servers, "Logical Server 1" running flow1 and flow3 and "Logical Server 2" running flow2. The Session Variable you have created in flow1 would be able to traverse through to flow3 but not flow2 because it is hosted in "Logical Server 2".

You will have to play around with my lab experiment to be able to better relate to what I am talking about and yes the diagram is an imaginary view, of course you wont see two servers in your Anypoint studio :P. It is there to help you understand what I see in my mind.






2 comments: