Thanksgiving Week Special – Get 50% OFF on FileTranz

Claim Your Offer

Exploring ObjectStore Operations in Anypoint Studio

Explore Object Store operations in Anypoint Studio to store, retrieve, check, and remove data for efficient state management in MuleSoft applications.

By Prasanna Saravanan
Assistant Software Developer

ObjectStore Components in Anypoint Studio

 

Every time I search the official documentation to learn about MuleSoft’s Object Store, I am left with more questions instead of answers. After spending hours, I decided to make a clear doccumentation about the ObjectStore in the Anypoint Studio. Let me share about the things I have learned and we are here to explore the interesting topics I have prepared in this blog.

Before we talk about the ObjectStore we need to discuss one thing. In apps, we often need to save temporary data in a database while we process a request. For example, an app might need to remember a user login, a one-timeOTP,  API key or access tokens for a short period. The usual method to achive this is by storing the value in the database and retrieve the data whenever needed. In that case, each time we need to process the request to database and retrieve the data.

To fix this problem MuleSoft gives us ObjectStore components. We can use ObjectStore components to do tasks, which makes our process much faster and easier.

ObjectStore:

The ObjectStore is a built-in way to store data in MuleSoft. It helps you save data, get data back and delete data. To put it simply the ObjectStore lets a Mule application remember information for a short time. This makes the integration process faster more efficient and easier to manage.

 

The below are the components that plays a major role in MuleSoft ObjectStore.

  • Store
  • Retrieve
  • Retrieve All
  • Retrieve All keys
  • Contains
  • Remove
  • Clear

1. ObjectStore:  Store

The Store operation is used to save data using Key-Value pairs. In this setup every piece of data has a key, like "id= 1". We use this unique id to find and manage our data inside the ObjectStore. People commonly use the Store operation to save the things like OTPs, user session details or cached API response tokens.

 

The below are the properties of Store:

Key: The Key is a name used to find a specific entry in the ObjectStore. You use the key when you want to store, find or delete a value.

If the payload looks like this:

//Payload
{
"id": 101  // This is the key used for storing values.
"name": "Prasanna"
}

Value: The Value is the data that gets saved along with the Key in the ObjectStore.

Fail if Present: This setting decides if the Store operation should fail if the Key already exists in the ObjectStore. This helps stop you from overwriting old data.

Fail on Null Value: This setting decides if the Store operation should fail if the data you are trying to save the null values. This is helpful if you do not want to save invalid data.

Object store: The Object store field lets you pick the name of the ObjectStore for the Store operation.

 
ObjectStore Configuration:

This is used to configure the ObjectStore settings globally. Here we can define the storage behavior, maximum entries, entry lifetime, and expiration settings.

Global ObjectStore Configuration:
  • Name: This is the name of the ObjectStore configuration. You use this name to find the ObjectStore settings.
  • Persistent: This decides if the ObjectStore should use storage. If you turn on persistence, the data will not be deleted if the applicaion restarts.
  • Max.Entries: This tells how much data want to store in the "Store" component. If we keep 1000, then it will stores the 1000 employees data inside it.
  • Entry TTL (Time To Live): This tells the duration of the data present inside the "Store" component. if you keep like 100 minutes then the data is present inside for 100 minutes.
  • Entry TTL Units: Here we can mention the time units for our entry ttl.
  • Expiration Interval: This is used to clear the entire expired data inside the objectStore. After this time the store component will delete the entire data which expires inside the “Store” component.
  • Expiration interval unit: Here we can mention the time units for our expiration interval.
  • Configuration Reference: This helps an ObjectStore operation point to a global ObjectStore configuration. It allows the operation to use the settings defined in the Global ObjectStore Configuration.
Default configuration:
  • Reconnect on failure: This tells Mule to try connecting to the ObjectStore if the connection fails.
  • Fails deployment when test connection failure: The application will fail to start if the connection test fails.
  • Reconnection strategy: Default: This uses a number of tries and a set amount of time between tries.
  • Frequency: This is how long Mule waits before it tries to reconnect.
  • Number of Reconnections: This is how many times Mule will try to reconnect.
  • Blocking: Mule will wait until the reconnection is finished before moving on.

Important things to note: We don't need to configure the remaining components like the "Store" component. The "Store" settings are already in the Global Configuration. So, you just pick the Configuration for all your components.

2. ObjectStore: Retrieve

The "Retrieve" component is used to retrieve the single data or value which is stored inside the "Store" component like key-valur pair.

Key: This is the unique id used to find the data inside the "Store" component. In this case we might use a URI Parameter to get the data from the "Store" component.

Default Value: This is the value used if the Key is not found in the "Store" component. For example if we look for employee details with "id": 101, but that "id" is not in the "Store" it will show a "not Found" message by default.

 

3. ObjectStore: Retrieve All

The " Retrieve All " component is used to retrieve all the values that are stored in the "Store" component. It returns the results as list of key-value pairs. The "Retrieve All" component is used when your application needs to read or to display every data that has been stored.

 

4. ObjectStore: Retrieve All Keys

The “Retrieve All Keys” component is used to retrieve a list of all the keys stored in the “Store” component. This is used to see what all are the keys are in your current "Store" component. 

 

5. ObjectStore: Contains

The “Contains” component is used to see whether the specific key is present in the "Store" or not. It doesn't give you the data in the format of key-value, it just gives a boolean value like "TRUE" or "FALSE". When the search key is present in the "Store", it gives the output as "TRUE" otherwise it will return a  "FALSE".

 

6. ObjectStore: Remove

The Remove component is used to delete a particular values inside the "Store" component by providing a key which is to identify the exact value. It removes the values that what we specifies and it will not affect the other data in the "Store" component. 

 

7. ObjectStore: Clear

The Clear component is used to delete the entire key values that present inside the "Store" component. It wipes out all the data in the "Store". The Remove component will delete one specific key and value but the "Clear" component will empty the entire Store. It is very helpful when old or temporary data is no longer useful.

 

Conclusion:

The overall conclusion is, The ObjectStore components are used for Storing and managing data with Mule applications. The key operation such as Store, Retrieve, Retrieve all, Retrieve all keys, Contains, Remove and Clear are very useful to achieve this. By using this, developer will make their work efficient when implementing state management, caching, watermarking, data persistence, and process tracking. Stay tuned for the next set of blogs from MuleSoft.

 

 


free-consultation