Working With Object Store in Mule, Part 1
In this first part of this series, we explore the concept of object stores and persistent stores, and how they relate to Mule apps.
Join the DZone community and get the full member experience.Join For Free
Mule Object Store
An Object Store Connector is one of the most useful connectors provided in the Mule runtime. It is used for storing the state of the application and can be shared across applications. Mule uses object stores whenever it needs data to persist for later retrieval. It 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.
Why Object Stores?
We often get the requirement where we need some application data to be used and shared across multiple applications. Though we can easily use a database for this purpose, where we have to query our DB to get this data, the disadvantage of this approach is whenever we need data we need to query our database. We can also use Object Store in Mule to make this a little easier.
Note: Internally, Mule uses object stores in various filters, routers, and other message processors that need to store state between messages. In most cases, Mule creates and manages object stores automatically, so no user configuration is necessary.
How to Download Object Store Connector
To use the Object Store module in Anypoint Studio, we must first download the Object Store Connector from the Anypoint Exchange. Alternatively, you can install it from Anypoint Studio.
Download Connector from the Anypoint Exchange:
Download Connector through Anypoint Studio:
In most cases, Mule creates and manages object stores automatically, so no configuration is necessary. However, you may explicitly configure an object store in the following cases:
When configuring an idempotent message filter or until a successful scope occurs.
When configuring a custom component that must use an object store to persist information.
When storing or retrieving information from a Mule flow through the Object Store module, this is available as an extension.
Mule Provides Two Types of Object Stores:
In-memory store – Stores objects in local Mule runtime memory. Objects are lost on the shutdown of the Mule runtime. Prior to Mule 3.5.0, in-memory store was the default. As of Mule 3.5.0, persistent store is the default.
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. In a standalone Mule runtime, Mule creates a default persistent store in the file system.
In the Next Post…
With these basics in mind, our next post, Working With Object Store in Mule - Part 2, we will see the operations supported by Object Store and how can we use them in an application.
Hope this helps, thanks!
Opinions expressed by DZone contributors are their own.