Working With Object Store in Mule, Part 2

DZone 's Guide to

Working With Object Store in Mule, Part 2

In this post, we pick up where Part 1 left off and check out some operations in XML that are supported by Mule's object store.

· Integration Zone ·
Free Resource

Mule's object store is a convenient way to store objects for later retrieval by key, essentially a key-value store. By default, this is in-memory, but it can also be easily changed to persist to file.

Below is the list of available operations supported by the Object store. The object store connector can perform various operations like Contains, Dual store, Remove, Retrieve, Retrieve all keys, Retrieve, and Store and Store.

1) All Keys

Returns a list of all the keys in the object store. It returns the java.util.List<String> with all the keys in the store.


<objectstore:retrieve-all-keys config-ref="ObjectStore__Configuration">

2) Contains

This operation Checks whether the object store contains the given key or not, it returns true if the object store contains the key, or false if it doesn't.


<objectstore:contains config-ref="ObjectStore__Configuration" key="member_id" doc:name="ObjectStore"/>

3) Remove

Remove the object from the respective key. It returns the object that was previously stored for the given key. If the key does not exist and ignoreNotExists is true the operation will return a null object.


<objectstore:remove config-ref="ObjectStore__Configuration" key="member_id" doc:name="ObjectStore"/>

4) Retrieve

Retrieve an object from the object store and make it available in the specified property scope of a Mule Message. It returns the object associated with the given key. If no object for the given key was found, this method throws an ObjectDoesNotExistException.


<objectstore:retrieve config-ref="ObjectStore__Configuration" key="#[message.inboundProperties.'http.query.params'.id]" doc:name="Retrieve Employee"/>

5) Retrieve store

This is when Retrieve and Store are in the same operation.

6) Store

Stores an object in the object store. This allows an option to indicate if the key would be overwritten or not. 

Note: If the method is not supported java.lang.UnsupportedOperationException is thrown.

In the Next Post…

That’s it! We have just understood the basics of object store and different operations supported by Object store. In our next post, Working With Object Store in Mule, Part 3, we’ll do some hands-on work in Anypoint Studio.

Hope this helps, thanks!

Keep learning!

anypoint studio, integration, mule, mule esb, object store

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}