DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Object Store Connector in Mulesoft
  • Configuring Amazon S3 Using Mulesoft
  • Designing a Java Connector for Software Integrations
  • Cutting-Edge Object Detection for Autonomous Vehicles: Advanced Transformers and Multi-Sensor Fusion

Trending

  • How Large Tech Companies Architect Resilient Systems for Millions of Users
  • Designing for Sustainability: The Rise of Green Software
  • Navigating Double and Triple Extortion Tactics
  • Unlocking the Potential of Apache Iceberg: A Comprehensive Analysis
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. Implementing Object Store With Mule ESB

Implementing Object Store With Mule ESB

Learn how you can install and implement the object store connector in Mule from the Anypoint exchange with the steps in this tutorial.

By 
Jitendra Bafna user avatar
Jitendra Bafna
DZone Core CORE ·
Jul. 06, 17 · Tutorial
Likes (9)
Comment
Save
Tweet
Share
50.0K Views

Join the DZone community and get the full member experience.

Join For Free

1.0 Overview

Object stores are used to store an object. Mule uses object stores whenever it needs data persistent for later retrieval. Mule uses object stores internally for various filters, routers, and other processors that need to store state between messages. By default, the object store connector not present in Mule palette. So you can install it from Anypoint exchange.

2.0 Object Store Operations

The object store connector can perform various operations like Contains, Dual store, Remove, Retrieve, Retrieve all keys, Retrieve and Store and Store.

  • Contains is used to verify if given key is present in the object store.

  • Dual store stores a value using a key and also stores a key using a value.

  • Remove is to remove the respective key from the object store.

  • Retrieve is used to retrieve an object from the object store and make it available in the specified property scope of a Mule Message.

  • Retrieve all keys will return a list of all keys present in the object store.

  • Retrieve and Store is used to retrieve and store an object in the same operation.

  • Store is used to store the object in an object store.

3.0 Types of Object Store

Mule provided two types of object store as follows

  • In-memory store: This allows you to store objects in memory at runtime. Generally, objects are lost when runtime is shutdown.

  • 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.

4.0 Object Store Use Cases

  • OAuth returns the token during an authorization request and this token needs to send with every request and it has expiration period (e.g. 2 hours). You can store the token in an object store so another flow or Mule application can retrieve that token from the object store to send requests to the client. Every two hours, a new token is generated and can be stored in the object store.

  • It can be used when configuring an idempotent filter or until successful scope.

  • It can be used when configuring a custom component that must use an object store to persist information.

  • It can be used when storing or retrieving information from a Mule flow through the Object Store module.

5.0 Installing Object Store Connector

The Anypoint Object Store Connector enables you to access to default in-memory object stores, custom object stores and persistent object stores. Using this connector, you can create instant connectivity between object stores and ease the manipulation of object stores in Mule.

If the object store connector is not found in the Anypoint Studio Mule palette, it can be installed from the Anypoint exchange. You can connect to the Anypoint exchange from Anypoint Studio and install the object store connector. Just you need to accept the license agreement and at the end it will ask to restart the Anpoint studio to complete installation.

Image title

6.0 Implementing the Idempotent Filter With In-Memory Object Store

  1. Place the HTTP Listener in the message source region and configure it.

  2. Drag and drop the Idempotent Filter in the message processor and configure the object store by clicking on the add button and selecting core:in-memory-store.

Image title

3. Configure Max Entries, Entry TTL, and Expiration Interval. Click Finish.

Image title

  • Entry Ttl is Time-To-Live for stored values in milliseconds. "Max Entries” and “Expiration Interval” are mandatory for using this param. You must either provide all Entry TTL, Max Entries, and Expiration Interval, or none of them.

  • Expiration interval specifies the expiration check in milliseconds.
  • Max Entries specifies the maximum number of entries.

4. Configure the Id Expression (i.e. MEL to identify the duplicate message on basis of the expression defined) and check Throw on Unaccepted (it will give control to error handling when a duplicate message is received.)

<?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">
    <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
    <flow name="idempotent-filter-object-storeFlow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/idempotent" allowedMethods="POST" doc:name="HTTP"/>
        <idempotent-message-filter idExpression="#[json:name]" throwOnUnaccepted="true" storePrefix="Idempotent_Message" doc:name="Idempotent Message">
            <in-memory-store name="InMemoryIdempotentFilter" maxEntries="60000" entryTTL="1200" expirationInterval="3600"/>
        </idempotent-message-filter>
        <set-payload value="Message Accepted." doc:name="Set Payload"/>
        <catch-exception-strategy doc:name="Catch Exception Strategy">
            <set-payload value="Message Unaccepted." doc:name="Set Payload"/>
        </catch-exception-strategy>
    </flow>
</mule>

7.0 Implementing the Idempotent Filter With Persistent Object Store

  1. Place the HTTP Listener in the message source region and configure it.
  2. Drag and drop the Idempotent Filter in the message processor and configure the object store by clicking on the add button and selecting core:simple-text-file-store.

Image title

3. Configure Max Entries, Entry TTL, Expiration Interval, and Directory (Directory is a file persistent store or file location where the object will be saved). Click Finish.

Image title4. Configure the Id Expression (i.e. MEL to identify the duplicate message on basis of the expression defined) and check Throw on Unaccepted (it will give control to error handling when a duplicate message is received.)

<?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">
    <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
    <flow name="idempotent-filter-object-storeFlow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/idempotent" allowedMethods="POST" doc:name="HTTP"/>
        <idempotent-message-filter idExpression="#[json:name]" throwOnUnaccepted="true" storePrefix="Idempotent_Message" doc:name="Idempotent Message">
            <simple-text-file-store name="InPersistentObjectStore" maxEntries="60000" entryTTL="1200" expirationInterval="3600" directory="src/test/resources/objectstore"/>
        </idempotent-message-filter>
        <set-payload value="Message Accepted." doc:name="Set Payload"/>
        <catch-exception-strategy doc:name="Catch Exception Strategy">
            <set-payload value="Message Unaccepted." doc:name="Set Payload"/>
        </catch-exception-strategy>
    </flow>
</mule>

8.0 Storing and Retrieving Custom Objects From the Object Store

8.1 Storing Objects in the Object Store

1. Place the HTTP Listener in the message source region and configure it. Here, we are expecting the query parameter and are going to store that query parameter in the object store.

2. Now, drag and drop the object store into the message processor and configure the object store connector configuration by clicking on the add button.

Image title

  • Partition is name of the default In-Memory or persistent object store.

  • Object Store Reference specifies the Object Store spring bean instance.

3. Select the operation to Store for storing the object. Provide the Key and Value Reference (i.e. Key=EmployeeID, ValueReference=#[message.inboundPrperties.’http.query.params.ID]).

8.2 Retrieving Objects From the Object Store

To retrieve the object from the object store, select the operation Retrieve and provide the key that you have used during the store operation (i.e. Key=EmployeeID). In case the key does not exist, it will throw an exception.

8.3 Mule Flow [Code]

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:objectstore="http://www.mulesoft.org/schema/mule/objectstore" 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
http://www.mulesoft.org/schema/mule/objectstore http://www.mulesoft.org/schema/mule/objectstore/current/mule-objectstore.xsd">
    <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
    <objectstore:config name="ObjectStore__Connector" partition="Emloyee" entryTtl="1200" expirationInterval="3600" maxEntries="60000" persistent="true" doc:name="ObjectStore: Connector"/>
    <flow name="object-store-appFlow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/object" allowedMethods="POST" doc:name="HTTP"/>
        <objectstore:retrieve-and-store config-ref="ObjectStore__Connector" key="EmployeeID" storeValue-ref="#[message.inboundPrperties.'http.query.params'.ID]" doc:name="ObjectStore"/>
    </flow>
    <flow name="object-store-appFlow1">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/retrieve" allowedMethods="GET" doc:name="HTTP"/>
        <objectstore:retrieve config-ref="ObjectStore__Connector" key="EmployeeID" doc:name="ObjectStore"/>
    </flow>
</mule>

8.4 Testing

You can use Postman to test the application. Please go through the below video and it will tell you how to perform testing for this Mule flow.

9.0 Object Store With Mule ESB [Video]


10.0 Conclusion

Object stores are very useful when you want to store the object and access it within or across the application. Objects can be stored in memory or a persistent file store.

Now you know how to use object stores in your Mule flow.

Object (computer science) Enterprise service bus Time to live Connector (mathematics)

Opinions expressed by DZone contributors are their own.

Related

  • Object Store Connector in Mulesoft
  • Configuring Amazon S3 Using Mulesoft
  • Designing a Java Connector for Software Integrations
  • Cutting-Edge Object Detection for Autonomous Vehicles: Advanced Transformers and Multi-Sensor Fusion

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!