Dealing with store the objectstore

30
Dealing with store – “The Object Store” By Anirban Sen Chowdhary

Transcript of Dealing with store the objectstore

Page 1: Dealing with store the objectstore

Dealing with store – “The Object Store”By Anirban Sen Chowdhary

Page 2: Dealing with store the objectstore

We often get into the situation where some data is require to persist for later retrieval and share across multiple application. Though we can easily use database for this purpose, but we can also use another facility called Object Store in Mule.Mule uses Object Store in various filters, routers, and other message processors that need store their state between messages.Most of the time Mule manages the Object Store automatically and no user configuration required. It’s very easy to use Object Store in Mule for storing data and sharing which we will explore now in our demonstration.

Page 3: Dealing with store the objectstore

Let’s consider we have 2 different application app1 and app2 which need to share data between them. Let both the application be under a domain called MyDomain.

Page 4: Dealing with store the objectstore

So, let’s start with our demonstration by creating a Mule Domain project called MyDomain

Page 5: Dealing with store the objectstore

In our Domain project MyDomain we will be defining Object Store spring bean mule-domain-config.xml.

Page 6: Dealing with store the objectstore

Now we will create two Mule application app1 and app2 to use the domain and share data between them

Page 7: Dealing with store the objectstore

We will deploy our Domain MyDomain along with two application app1 and app2 in Mule server:-

Page 8: Dealing with store the objectstore

In App1, we will store data into Object Store .We will store the data in the Object Store by adding a key which will increment by 1 whenever adding a new data to the Object Store :-

We are using the tag <objectstore:store/> to store data.

Page 9: Dealing with store the objectstore

Adding data to Object Store from app1.

Page 10: Dealing with store the objectstore

Let’s add few data to Object Store from app1 by posting payload to the API. Here we are sending JSON payload with id=01 and name=Anirban.

Page 11: Dealing with store the objectstore

Again we will hit the service and send JSON payload with id=002 and name=Mike.

Page 12: Dealing with store the objectstore

We will repeat the process one more time and hit the service and send JSON payload with id=027 and name=David.Now we have added few data to our Object Store from app1.

Page 13: Dealing with store the objectstore

Retrieving all the keys from app2

Page 14: Dealing with store the objectstore

Now, from app2, we will retrieve all the key from the Object Store of all the data that we inserted into it from app1.We will use tag <objectstore:all-keys/> to retrieve all the Keys.

Page 15: Dealing with store the objectstore

Whenever we will hit http://localhost:8085/getallkeys all the keys associated with the data. Here there will be 3 keys :- 1,2 and 3 for all 3 data we have inserted into Object Store.

Page 16: Dealing with store the objectstore

Retrieving all the values from app2

Page 17: Dealing with store the objectstore

Here we will retrieve all the values we inserted into Object Store from app1 along with their key from app2.We will use <objectstore:retrieve/> to achieve this within a for loop.

Page 18: Dealing with store the objectstore

When we hit the url http://localhost:8085/getallvalues we get all the values along with the keys associated.

Page 19: Dealing with store the objectstore

Retrieving a particular value from app2

Page 20: Dealing with store the objectstore

Here we will retrieve a particular value we inserted into Object Store from app1 by passing it’s associate key in the url as uri param from app2.We will use <objectstore:retrieve/> to achieve this by passing the key dynamically from uri param.

Page 21: Dealing with store the objectstore

When we hit the url http://localhost:8085/retrieve/1 where 1 is the key we are passing as uri param to get the value associate with the key.

Page 22: Dealing with store the objectstore

Deleting a particular value from app2

Page 23: Dealing with store the objectstore

Likewise to delete a particular value from app2, we can pass the key id in the url .We will use <objectstore:remove/> tag to remove a value.

Page 24: Dealing with store the objectstore

When we hit the url http://localhost:8085/remove/2 where 2 is the key we are passing as uri param to delete the value associate with the key.Here the data associated with key=2 will be deleted.

Page 25: Dealing with store the objectstore

Deleting all the values from app2

Page 26: Dealing with store the objectstore

To delete all the values in Object Store from app2, we can construct the following flow in app2.We will use <objectstore:remove/> tag inside for loop to remove all values :-

Page 27: Dealing with store the objectstore

When we hit the url http://localhost:8085/removeallvalues all the data will be removed from the Object Store.

Page 28: Dealing with store the objectstore

Conclusion…..

Page 29: Dealing with store the objectstore

Here it was a small demonstration on using Object Store across multiple application to share data between them.Mule uses Object Stores whenever it needs data to persist for later retrieval. So at the end I can only say that, let’s spread our knowledge and expand our Mule community.

Page 30: Dealing with store the objectstore

Thank You