Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Object Store Connector in Mule ESB

DZone's Guide to

Object Store Connector in Mule ESB

Want to learn more about object stores? Read this tutorial in order to learn more!

· Integration Zone ·
Free Resource

SnapLogic is the leading self-service enterprise-grade integration platform. Download the 2018 GartnerMagic Quadrant for Enterprise iPaaS or play around on the platform, risk free, for 30 days.

Object store is a famous concept in Mulesoft for storing and retrieving objects.

Real-Time Scenarios

Calling a different OAuth2.0 secured API at regular intervals of time. In Mule projects, the Object store is mainly used to store Tokens for API calling purpose.

Example:

Working with OAuth 2.0, you need a "security_token" to call a secured API. These tokens can be retrived by calling 3rd Party trusted API by providing client_id & client_secret. Object store can store these security_token and can be pass in as query parameter while calling API. Every time you get a new "security_token" by trusted API so you have to update it every time with new token.

It's not a problem if you are calling a single API, but calling Multiple APIs at regular intervals of time can create a hassle.

Object Store Uses Two Types of Stores:

1. In-memory store: Stores objects in local Mule runtime memory.

ie. Stopping the application from deleting all the information present in the object store.

2. Persistent store: Mule persists data when an object store is explicitly configured to be persistent. Mule creates a default persistent store in the file system.

Methods Available in Object Store Connector:

1. Contains:

Image title

Checks Object store for supplied Key. (checks for client_name)

If Key is present, return TRUE

If not, return FALSE

2. Store:

It stores an object in the object store for the specified key.

Image title

It has one option --> Override:

If checked: it will override Duplicate key's value.

If Unchecked: It will throw "org.mule.api.store.ObjectAlreadyExistsException" for duplicate key.

3. Retrieve All Keys:

It will retrieve all keys present in that object store. It returns the java.util.List<String> with all the keys in the store.

eg. [ key1, key2, key3 ...]

Image title

4. Remove:

It removes the object from the object store. It will return the object, which was stored previously for the key.

Image titleIt has one option --> Ignore Not Exist

If checked: it will return {NullPayload} if the key is unavailable.

If unchecked: It will throw "org.mule.api.store.ObjectDoesNotExistException" for unavailable key.

5. Retrieve:

Retrieves an object from the object store and copies the retrieved value into the specified property scope of a Mule message. The default target property scope is INVOCATION.

Scenario: You will come with a situation where you need to fetch a person's information from the object store using a query parameter and pass that value to a session variable so that other applications can use it.

In this case, "Retrieve" is the best option.

The configuration of Object store retrieves the operation shown below.

Image title

The result of the above configuration is shown below.

Image title

Here, you can see the session variable is set and payload os of {nullPayload}

Target scope: Outbound, when you want to store information as a property using Set Property

If no object for the given key was found, this method throws an ObjectDoesNotExistException.

6. Retrieve and Store:

This Method is used when you want to retrieve and store information in the object store at the same time.

Scenario:

When you want to constantly update new information of people and pass that updated information to other applications using session variable.

eg. I have passed my information 2 times where every time a new field is added in JSON.

Image 1

Image 2I have added two fields for two different requests (image for reference).

ie. "Technology" for 1st and "Country" for 2nd.

7. Dual Store:

Stores the value object using the supplied key and also stores the key object using the supplied value. This is equivalent to calling Store(key,value) and Store(value,key) in a single operation.

This allows you to later retrieve the key object by supplying the value object instead of only retrieving the value object by supplying the key object.

In short, you usually search the "value" using "key," but in this case, you can search "Key" using "value." So, both ways are possible.

Hope this helps! :)

Download A Buyer's Guide to Application and Data Integration, your one-stop-shop for research, checklists, and explanations for an application and data integration solution.

Topics:
mule esb ,integration ,object store ,connector ,stores ,mule ,mulesoft ,esb

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}