13
Mapping and Listing with Mule( For beginners )

Mapping and listing with mule

Embed Size (px)

Citation preview

Page 1: Mapping and listing with mule

Mapping and Listing with Mule( For beginners )

Page 2: Mapping and listing with mule

Mule ESB has the ability to store data into variables. Fortunately Mule offers 2 types of variables 1) Flow variables that has scope limited to a flow and subflow and 2) Session variables that has scope and can be accessed from entire application.Now, one interesting facts I come across several Mule users is how to define a List or a Map with a variable in Mule in the same way as Java.Let me tell you, this is absolutely possible with Mule.We can define List or a Map in Mule with Mule variables.

Page 3: Mapping and listing with mule

How can we use Mule variables as a List or a Map ? 

Page 4: Mapping and listing with mule

We can define a List with a Mule variable in following ways :-

<set-variable variableName="test" value="#[{1000,100,14,1}]" doc:name="Variable"/>Or

<set-variable variableName="test" value="#[[1000,100,14,1]]" doc:name="Variable"/>Here you can see we define a variable named as test which is defined as a List

Page 5: Mapping and listing with mule

Now, we can get the values from the List as follow :-

<logger level="INFO" message="#[flowVars['test'][0]]" doc:name="Logger"/><logger level="INFO" message="#[flowVars['test'][1]]" doc:name="Logger"/><logger level="INFO" message="#[flowVars['test'][2]]" doc:name="Logger"/><logger level="INFO" message="#[flowVars['test'][3]]" doc:name="Logger"/>

As you can see we are retrieving the values from the List with the index

Page 6: Mapping and listing with mule

Now, we can define a Map in the same way as follow :-

<set-variable variableName="customMap" value="#[{'k2':'new', 'k3':'v3'}]" />Or<set-variable variableName="customMap" value="#[['k2':'new', 'k3':'v3‘]]" /> Here you can see we define a variable named as customMap which is defined as a Map

Page 7: Mapping and listing with mule

Now, we can get the values from the Map as follow :-

<logger message="#[flowVars['customMap']['k2']] " level="INFO" doc:name="Logger"/><logger message="#[flowVars['customMap']['k3']] " level="INFO" doc:name="Logger"/> As you can see we are retrieving the values from the Map with the key

Page 8: Mapping and listing with mule

Now, let us consider a simple flow to demonstrate the List and the Map as follow :-

Page 9: Mapping and listing with mule

The Mule config will be :-

You can see here we are using Expression component to reassign our List value of index 1 and index 2 … Then we are using logger to print the new value of List again in the console

Page 10: Mapping and listing with mule

So, if we test the example we will get all the value of List and Map variables as follow as well as with new reassigned value :-

Page 11: Mapping and listing with mule

So, here you can see how to use a List and Map with Mule variable… Hope I was clear enough to give an Idea of it’s implementation ….

Page 12: Mapping and listing with mule

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

Page 13: Mapping and listing with mule

Thank You