<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
<!-- Global object store definition for a Listable Object Store, used in Flow 3 below. -->
<spring:beans>
<spring:bean id="myListableObjectStore" class="org.mule.util.store.SimpleMemoryObjectStore"/>
</spring:beans>
<http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="8081" doc:name="HTTP Listener Configuration"/>
<!-- Idempotent Filter with In Memory Object Store -->
<flow name="Flow1_idempotentWithInMemoryStore" doc:name="Flow1_idempotentWithInMemoryStore">
<http:listener config-ref="HTTP_Listener_Configuration" path="idempotentInMemory" doc:name="HTTP"/>
<idempotent-message-filter idExpression="#[message.payload]" throwOnUnaccepted="true" storePrefix="Idempotent_Message" doc:name="Idempotent Message">
<in-memory-store name="myInMemoryObjectStore" entryTTL="120" expirationInterval="3600" maxEntries="60000" />
</idempotent-message-filter>
<set-payload value="YAY!" doc:name="Set Payload" />
<catch-exception-strategy doc:name="Catch Exception Strategy">
<set-payload value="NAY!" doc:name="Set Payload" />
</catch-exception-strategy>
</flow>
<!-- Idempotent Filter with Persistent File Store -->
<flow name="Flow2_idempotentWithTextFileStore" doc:name="Flow2_idempotentWithTextFileStore">
<http:listener config-ref="HTTP_Listener_Configuration" path="idempotentTextFile" doc:name="HTTP"/>
<idempotent-message-filter idExpression="#[message.payload]" throwOnUnaccepted="true" storePrefix="Idempotent_Message" doc:name="Idempotent Message">
<simple-text-file-store
name="mySimpleTextFileStore"
directory="#[server.tmpDir + '/objectstore']"
entryTTL="120"
expirationInterval="3600"
maxEntries="60000" />
</idempotent-message-filter>
<set-payload value="YAY!" doc:name="Set Payload" />
<catch-exception-strategy doc:name="Catch Exception Strategy">
<set-payload value="NAY!" doc:name="Set Payload" />
</catch-exception-strategy>
</flow>
<!-- Until Successful Scope with In Memory Object Store -->
<flow name="Flow3_UntilSuccessfulWithListableObjectStore" doc:name="UntilSuccessfulWithListableObjectStore">
<http:listener config-ref="HTTP_Listener_Configuration" path="hey" doc:name="HTTP"/>
<until-successful objectStore-ref="myListableObjectStore" maxRetries="15" secondsBetweenRetries="1" doc:name="Until Successful">
<processor-chain doc:name="Processor Chain">
<message-filter throwOnUnaccepted="true">
<expression-filter expression="return Math.random() < 0.1" doc:name="Expression" />
</message-filter>
<logger message="This eventually happens." doc:name="Logger" />
</processor-chain>
</until-successful>
<set-payload value="Completed" doc:name="Set Payload" />
</flow>
</mule>
Mule Object Stores
Mule runtime engine version 3.8 reached its End of Life on November 16, 2021. For more information, contact your Customer Success Manager to determine how to migrate to the latest Mule version. |
An object store is a facility for storing objects in or across Mule applications. Mule uses object stores to persist data for eventual retrieval. Internally, Mule uses object stores in various filters, routers, and other message processors that need to store state between messages.
MuleSoft provides two types object stores:
-
On Premises Object Store - This object store persists key-value pairs in memory for an application when Mule is used on premises. This object store is only limited by available memory, works with any on-premises Mule version, and can be set to be persistent or to only exist as long as Mule is running.
-
Cloud Object Store - This cloud-only object store is available from multiple datacenters around the world, can have an unlimited number of keys, up to 10 MB values, and an unlimited amount of data. Data can persist for up to 30 days in Object Store v2. Object Store v2 is supported for Mule 3.8.5 and later, and all Mule 4 applications. Mule 4 cloud applications can only use Object Store v2. MuleSoft is transitioning away from the legacy Object Store v1 which only works in Mule 3 applications.
To learn about Object Store v1 management in Runtime Manager, see Managing Application Data with Object Stores or more generally, Configuring an Object Store for Cache.
See also Object Store v2.
To access and manipulate object stores in Mule applications, download the Object Store connector in Anypoint Studio. The Object Store connector works with both Object Store v1 and Object Store v2. |
Use Cases
You may explicitly configure an object store when configuring:
-
An idempotent message filter or until a successful scope occurs.
-
The idempotent redelivery policy of a custom endpoint.
-
An aggregator, you can either use the two default built-in object stores or create a reference of your own.
-
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 connector, available for installation
Mule provides two types of on-premises object stores:
-
In-memory store – stores objects in local Mule runtime memory. Objects are lost on shutdown of the Mule runtime.
-
Persistent store – Mule persists data when an object store is explicitly configured to be persistent. In a standalone Mule runtime, Mule creates a default persistent store in the file system. See also: About Persisting Object Stores in Runtime Manager
If you do not specify an object store, the default persistent object store is used.
For more information, see the Object Stores and Clustering section of the Cache Scope document.
Tip: The on-premises object store created for new caching strategies supports cluster mode out of the box, with the exception of the cache scope which uses the old default caching strategy.
XML Example
The following example demonstrates how to configure object stores in the following three situations:
-
idempotent filter with an in-memory object store.
-
idempotent filter with a persistent object store.
-
Until a successful scope occurs with an in-memory object store.
See Also
-
Install the Object Store connector in Anypoint Exchange.
-
Learn about the Runtime Manager implementation of object stores.