Contact Free trial Login

Tutorial: Object Store v2

Use this tutorial to begin using Object Store v2 to store and view data.

You can send any serializable data as key-value pairs to the object store.

In this tutorial, you create two apps, one in Design Center and one in Anypoint Studio:

  1. Configure Anypoint Connector for Object Store (Object Store Connector) in the app.

  2. Send data to the object store.

  3. View data in Runtime Manager.

Depending on your Mule version, you create your app in Studio 7 (Mule 4) or Studio 6 (Mule 3).

Prerequisites

  • Familiarity with Anypoint Studio, Anypoint Platform, and Runtime Manager

  • An Anypoint Platform account

    If you don’t have an Anypoint Platform login, click Sign up on the Anypoint Platform sign-in page.

  • A Design environment configured in Anypoint Platform Access Management > Environments.

    If you don’t see Access Management, contact your site administrator.

  • Anypoint Studio installed on your system:

  • A curl command for testing

    This tutorial uses the HTTP Listener trigger to initiate Object Store Connector access and a curl command to send JSON data to your Mule app.

    Instead of curl, you can use Postman or browser plugins.

Disable password programs such as LastPass or Okta in your browser before using Design Center. If enabled, the password program inserts passwords in fields in Design Center, which can cause the app to fail.

Create an App with an Object Store in Design Center

You use Design Center to configure an app that includes an HTTP Listener trigger and Object Store Connector. Then, you can use a curl command to send a key and value, and view the key in Runtime Manager.

To configure an app in Design Center:

  1. In Anypoint Platform, click Design Center in the left navigation bar or the main Anypoint Platform screen.

  2. Click Create new > Create new application:

    Create new application option
    Figure 1. The arrow shows the Create new application option.
  3. In the New Mule Application window, enter osv2demo for the project name and click Create.

  4. In the wizard, click Go straight to canvas:

    Go straight to canvas option
    Figure 2. The arrow shows the Go straight to canvas option.
  5. Click Trigger and enter H to search for HTTP Listener:

    Search for HTTP Listener
    Figure 3. The arrow shows HTTP Listener.
  6. Click HTTP Listener.

  7. In the HTTP Listener window, set the value of Path to /store and then click the close button (X):

    Path value and close button (X)
    Figure 4. The screenshot shows (1) the Path value and (2) the close button (X).

    Because the default settings for HTTP Listener are correct, you don’t need to click Edit.

  8. Click the plus icon (+) to the right of the HTTP Listener trigger:

    Plus icon
    Figure 5. The arrow shows the plus icon (+).
  9. In the Select a component window, enter ob to search for ObjectStore Connector:

    Search for ObjectStore Connector
    Figure 6. The arrow shows ObjectStore Connector.
  10. Click the connector and then click the Store operation:

    Store operation
    Figure 7. The arrow shows the Store operation.
  11. In the Configuration tab, specify #[payload.key] in the Key field and payload.value in the Value field:

    Key and Value fields for the Store operation
    Figure 8. The screenshot shows (1) the Key field and (2) the Value field.

    The maximum number of characters in a key is 256.

  12. Click Test to run the app in a temporary location.

    The app starts running in a temporary environment:

    The osv2demo app running in a temporary environment
    Figure 9. The arrow shows a message indicating the osv2demo app is running in a temporary environment.

You have successfully used Design Center to configure and deploy an app with an object store to a temporary environment.

Next, you test the connection by submitting REST API commands to the Object Store API and using Runtime Manager to view the results.

Test Your Design Center App

After you create your app in Design Center, you test your app using a curl command to submit a REST API command to the Object Store API and use Runtime Manager to view the results.

To test your app:

  1. Click the copy icon to copy the deployment URL:

    The copy deployment URL icon
    Figure 10. The arrow shows the deployment URL copy icon.
  2. From the command line, use curl command to send a key-value pair to the object store, replacing DEPLOYMENT-URL with the deployment URL you copied from Design Center:

    curl -X POST \
      "http://DEPLOYMENT-URL/store"
      -H "Content-Type: application/json"
      -d '{ "key": "myKey", "value": "OSv2 Test" }'

    The output from this command is:

    { "key": "myKey", "value": "OSv2 Test" }
  3. Select View in Runtime Manager from the …​ menu in the right corner:

    View in Runtime Manager menu option
    Figure 11. The arrow shows the …​ menu and View in Runtime Manager option in Design Center.
  4. In Runtime Manager, click Object Store in the left navigation pane.

  5. Click the object store, the partition, and then the key:

    Key and value in the object store in Runtime Manager
    Figure 12. The screenshot shows (1) the object store, (2) the key, and (3) the value in the object store.

    You see that the myKey key that you sent from curl appears in the object store with the value of [binary value] BINARY.

    The myKey key that you sent from curl appears in the object store with the value of [binary value] BINARY. The value is binary because Mule 4 wraps values in a Mule object, which causes them to be visible only as binary in Anypoint Platform.

You have successfully tested your app using a curl command to store a key-value pair in the object store and viewed the results in Runtime Manager.

To verify that the value is correct, return to Design Center and add a new flow that retrieves the value.

Create a Flow to Retrieve the Value

To create a new flow to retrieve the 'myKey` value:

  1. In Design Center, in the Project area on the left, expand the Flows menu.

  2. Select Rename from the vertical ellipsis menu and rename your existing flow from New Flow to Store:

    Vertical ellipsis menu and Rename option
    Figure 13. The screenshot shows (1) the vertical ellipsis menu and (2) the Rename option.
  3. Click the plus sign to the right of Flows.

  4. In the wizard, click Go straight to canvas:

    Go straight to canvas option
    Figure 14. The arrow shows the Go straight to canvas option.
  5. Click the Trigger box and enter H to search for HTTP Listener:

    Search for HTTP Listener
    Figure 15. The arrow shows the HTTP Listener.
  6. Click HTTP Listener.

  7. In the HTTP Listener window, set the value of Path to /retrieve and then click the close button (X):

    Path value and close button (X)
    Figure 16. The screenshot shows (1) the Path value and (2) the close button (X).

    Because the default settings for HTTP Listener are correct, you don’t need to click Edit.

  8. Rename this new flow to Retrieve.

  9. Click the plus icon (+) to the right of the HTTP Listener trigger to add Object Store Connector.

  10. In the Select a component window, enter ob to search for ObjectStore Connector:

    Search for Object Store Connector
    Figure 17. The arrow shows ObjectStore Connector.
  11. Click the connector and then click the Retrieve operation.

  12. In the Configuration tab, specify #[attributes.queryParams.key] in the Key field:

    Key field for the Retrieve operation
    Figure 18. The arrow shows the Key field in the Retrieve configuration.
  13. Click Test to run the app in a temporary location.

  14. Click the copy icon to copy the deployment URL:

    The copy deployment URL icon
    Figure 19. The arrow shows the deployment URL copy icon.
  15. From the command line, run the following curl command to retrieve the key, replacing DEPLOYMENT-URL with the deployment URL that you copied from Design Center:

    curl http://DEPLOYMENT-URL/retrieve?key=myKey;echo

    The output from this command displays the value for the myKey:

    "OSv2 Test"

You have successfully tested your app using a curl command to submit a REST API command to the Object Store API and to retrieve the results.

Next, you create a Mule app in Anypoint Studio 7 and add an object store.

Create a Mule 4 App with an Object Store in Anypoint Studio 7

You can now use Anypoint Studio 7 to create a Mule 4 app similar to the app you created in Design Center.

First, you use Studio 7 to configure an app that includes an HTTP Listener trigger and Object Store Connector. Then, you deploy the app to CloudHub and use a curl command to send a key and value, and view the key in Runtime Manager.

To configure a Mule 4 app in Studio 7:

  1. Start Studio, click File > New > Mule Project, name the project osv2-demo, and then click Finish.

  2. Install Object Store Connector:

    1. Click the Exchange icon in the toolbar:

      Exchange icon in the Studio 7 toolbar
      Figure 20. The arrow shows the Exchange icon in the Studio 7 toolbar.
    2. Enter your Anypoint Platform username and password, if prompted.

    3. In Exchange, select Provided by MuleSoft and then search for ObjectStore Connector:

      Provided by MuleSoft option and search field in Exchange
      Figure 21. The screenshot shows (1) the Provided by MuleSoft option and (2) the search field.
    4. Select ObjectStore Connector - Mule 4.

    5. Click Add to project:

      Add to project icon in Exchange
      Figure 22. The arrow shows the Add to project icon in Exchange.
    6. At the confirmation prompt, click Proceed and then click OK.

  3. In the Mule Palette view, click HTTP, and then drag Listener to the Studio canvas:

    HTTP Connector and Listener operations in the Mule Palette view
    Figure 23. The screenshot shows (1) HTTP Connector and (2) the Listener operation.
  4. Click ObjectStore and then drag the Store operation to the right of Listener on the canvas.

    Store operation in the Studio 7 canvas
    Figure 24. The arrow shows the Store operation in the Studio 7 canvas.
  5. In the canvas, click Listener.

  6. In the Listener properties window, set General > Path to /store.

  7. Click the green plus icon (+) to the right of the Connector configuration field.

  8. In the HTTP Listener Global Element Properties window, verify that Host is set to 0.0.0.0 and Port is set to 8081, and then click OK.

    The Listener properties window indicates that there are no errors:

    Listener properties
    Figure 25. The screenshot shows (1) the Path property and (2) the Connector configuration icon for the Listener operation.
  9. In the canvas, click the Store operation.

  10. In the Store properties window, specify #[payload.key] in the Key field and payload.value in the Value field:

    Key and Value fields for the Store operation
    Figure 26. The screenshot shows (1) the Key field and (2) the Value field for the Store operation.

    The maximum number of characters in a key is 256.

    To use Object Store v2 with Mule 4 apps, do not select an object store global element from the Object store menu. If you select the object store global element, the app uses the Mule runtime object store, rather than Object Store v2.

  11. Select the flow and, in the properties window, change the name to Store:

    Name field in the Store flow properties window
    Figure 27. The arrow shows the Name field in the Store flow properties window.
  12. In the Mule Palette view, click HTTP and then drag another Listener to the canvas below the first flow.

  13. Click ObjectStore and then drag the Retrieve operation to the right of Listener in the second flow.

  14. In the canvas, click Listener.

  15. In the Listener properties window, set General > Path to /retrieve.

  16. In the Connector configuration menu, select the same HTTP_Listener_config option that you set up for the Listener operation in the Store flow:

    Connector configuration menu in the Listener properties window
    Figure 28. The arrow shows the Connector configuration menu in the Listener properties window.
  17. In the canvas, click the Retrieve operation.

  18. In the Retrieve properties window, specify #[attributes.queryParams.key] in the Key field:

    Key field for the Retrieve operation
    Figure 29. The arrow shows the Key field in the Retrieve properties window.
    Do not select an object store global element from the Object store menu.
  19. Select the second flow and, in the properties window, change the name to Retrieve.

    When you are done, the flows should look like this:

    Store and Retrieve flows in Studio
    Figure 30. The screenshot shows (1) the Store flow and (2) the Retrieve flow.
  20. In Package Explorer in Studio, right-click osv2-demo and select Anypoint Platform > Deploy to CloudHub.

  21. At the prompt, select the environment to deploy the app to.

  22. In the Anypoint Platform Deploying Application window, click Deploy Application:

    Deploy Application button in the Deploying Application page
    Figure 31. The arrow shows the Deploy Application button in the Deploying Application page.
  23. Click Open in Browser to display the app in Runtime Manager.

    If CloudHub displays a permissions error, select a different environment to deploy to.

You have successfully used Studio 7 to configure an app with an object store. Next, you test the connection by submitting REST API commands to the Object Store API and using Runtime Manager to view the results.

Test Your Studio 7 Application

After you create your app in Studio 7, you can test it using a curl command to submit a REST API command to the Object Store API and use Runtime Manager to view the results.

To test your app:

  1. In Runtime Manager, click Applications and ensure that the osv2-demo app is running.

  2. Click the Status column for the osv2-demo app to display its details in the right pane.

  3. Copy the App url value:

    App url in Runtime Manager
    Figure 32. The arrow shows App url in the details pane in Runtime Manager.
  4. From the command line, run the following curl command, replacing APP-URL with the App url value that you copied from Runtime Manager:

    $ curl -X POST -H "Content-Type: application/json" -d '{ "key": "myKey", "value": "OSv2 Test" }' "http://APP-URL/store";echo

    The output from this command displays the key-value pair that you sent to the object store:

    { "key": "myKey", "value": "OSv2 Test" }
  5. In Runtime Manager, click Manage application in the details pane for the application:

    Manage application in the details pane
    Figure 33. The arrow shows Manage application in the details pane in Runtime Manager.
  6. Click Object Store in the left navigation pane.

  7. Click the object store, the partition, and then the key:

    Object Store option
    Figure 34. The screenshot shows (1) the Object Store option, (2) the key, and (3) the value in the object store.

    The myKey key that you sent from curl appears in the object store with the value of [binary value] BINARY. The value is binary because Mule 4 wraps values in a Mule object, which causes them to be visible only as binary in Anypoint Platform.

  8. From the command line, run the following curl command to view the value for the key, replacing APP-URL with the App url value that you copied from Runtime Manager:

    curl http://APP-URL/retrieve?key=myKey;echo

    The output from this command displays the value for the key:

    "OSv2 Test"

You have successfully tested your app using a curl command to store and retrieve a key-value pair in the object store and viewed the results in Runtime Manager.

Studio 7 XML

You can use XML to create the osv2-demo app in Studio 7 by clicking Configuration XML tab in Studio, comparing your XML to the following, and making corrections as needed:

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:os="http://www.mulesoft.org/schema/mule/os" 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:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="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/os http://www.mulesoft.org/schema/mule/os/current/mule-os.xsd">
  <http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="24b76402-e396-4228-a48e-fcd9ac651488" >
    <http:listener-connection host="0.0.0.0" port="8081" />
  </http:listener-config>
  <os:object-store name="Object_store" doc:name="Object store" doc:id="acb3bf59-becf-4b86-901d-97f6903fcfc0" />
  <os:object-store name="Object_store1" doc:name="Object store" doc:id="3b262a2e-ca98-4c68-bd21-d3d40a3812c7" />
  <flow name="Store" doc:id="e7d253f9-534b-41df-a189-de815a42facb" >
    <http:listener doc:name="Listener" doc:id="805c84ec-35d4-4753-846b-49b108044df7" config-ref="HTTP_Listener_config" path="/store"/>
    <os:store doc:name="Store" doc:id="d4800501-0fa8-4472-a23e-5213f04155e8" key="#[payload.key]">
      <os:value ><![CDATA[#[payload.value]]]></os:value>
    </os:store>
  </flow>
  <flow name="Retrieve" doc:id="1db04ffc-76c1-48b4-ba33-57807a6404a8" >
    <http:listener doc:name="Listener" doc:id="faed2a0f-3005-4244-a6c6-77407b34d53a" path="/retrieve" config-ref="HTTP_Listener_config"/>
    <os:retrieve doc:name="Retrieve" doc:id="3f907cfc-59e5-49cd-879a-7b2675d488a5" key="#[attributes.queryParams.key]">
      <os:default-value ><![CDATA[#["TEST"]]]></os:default-value>
    </os:retrieve>
  </flow>
</mule>

Create a Mule 3 App with an Object Store in Anypoint Studio 6

You can use Anypoint Studio 6 to create a Mule 3 app similar to the app you created in Design Center. First, you use Studio to configure an app that includes Object Store Connector. Then, you deploy the app CloudHub and use a curl command to send a key and value, and view the key in Runtime Manager.

To configure a Mule 3 app in Studio 6:

  1. Start Studio, click File > New > Mule Project, name the project osv2-demo-studio-6, and then click Finish.

  2. Install Object Store Connector:

    1. Click the Exchange icon in the toolbar:

      Exchange icon in the Studio 6 toolbar
      Figure 35. The arrow shows the Exchange icon in the Studio 6 toolbar.
    2. Enter your Anypoint Platform username and password, if prompted.

    3. In Exchange, select Provided by MuleSoft and then search for ObjectStore Connector:

      Provided by MuleSoft option and search field in Exchange
      Figure 36. The screenshot shows (1) the Provided by MuleSoft option and (2) the search field.
    4. Select Object Store Connector - Mule 3.

    5. Click Install:

      Install icon in Exchange
      Figure 37. The arrow shows the Install icon in Exchange.
    6. At the prompt, check the items to install and click Next twice.

    7. Accept the license agreement and click Finish.

    8. At the prompt, click Restart Now to finish installing the connector.

  3. In the Mule Palette view:

    1. Drag HTTP to the Studio canvas:

      HTTP Connector in the Mule Palette view
      Figure 38. The arrow shows HTTP Connector.
    2. Search for string and then drag Object to String to the Process area to the right of HTTP on the canvas.

    3. Search for json and then drag JSON to Object to the canvas to the right of Object to String.

    4. Search for objects and then drag ObjectStore to the canvas to the right of JSON to Object.

    5. Search for payload and then drag Set Payload to the canvas to the right of ObjectStore.

      The flow should look like this:

      Flow in Studio 6 canvas
      Figure 39. The arrow shows the flow in the canvas.
  4. In the canvas, click HTTP.

  5. In the HTTP properties window:

    1. Set Path to /store and Allowed Methods to POST.

      When you submit a curl command, you append the /store option to the URL. The Allowed Methods setting ensures that the curl command can only POST information to the object store.

    2. Click the green plus icon (+) to the right of Connector Configuration.

    3. In the HTTP Connector Global Element Properties window, verify that Host is set to 0.0.0.0 and Port is set to 8081, and then click OK.

      The HTTP properties window now indicates that there are no errors:

      HTTP properties in Studio 6
      Figure 40. The arrow shows the HTTP properties window.
  6. In the canvas, click JSON to Object and then set Return Class to java.util.Map:

    JSON to Object properties in Studio 6
    Figure 41. The arrow shows the Return Class field in the JSON to Object properties window.
  7. In the canvas, click ObjectStore.

  8. In the ObjectStore properties window:

    1. Set the Operation to Store and set these store operation values:

      • Set Key to #[payload.key].

        The maximum number of characters in a key is 256.

      • Set Value Reference to #[payload.value].

    2. Click the green plus icon (+) to the right of Connector Configuration.

    3. In the ObjectStore Connector Global Element Properties window, set Partition to myPartition and Object Store Reference to _defaultUserObjectStore, and then click OK.

      Partition and Object Store Reference fields in the Global Element Properties window
      Figure 42. The screenshot shows (1) the Partition field and (2) the Object Store Reference field in the Global Element Properties window.
      The Object Store Reference field must be set to _defaultUserObjectStore for data to be stored in Object Store v2.

      The ObjectStore properties window now indicates that there are no errors:

      ObjectStore properties in Studio 6
      Figure 43. The arrow shows the ObjectStore properties window.
  9. In the canvas, click Set Payload.

  10. In the Set Payload properties window, set the Value field to:

    KEY: #[payload.key] AND VALUE: #[payload.value] WERE SAVED

    This message appears on the command line to indicate that the curl command values are received by the application:

    Value field in the Set Payload properties window
    Figure 44. The arrow shows the Value field in the Set Payload properties window.
  11. Save your project.

  12. In Package Explorer in Studio, right-click osv2-demo-studio-6 and select Anypoint Platform > Deploy to Cloud.

  13. At the prompt, select the environment to deploy the app to.

  14. In the Anypoint Platform Deploying Application window, ensure that Use Object Store v2 is selected and then click Deploy Application:

    Deploy Application button in the Deploying Applications page
    Figure 45. The arrow shows the Deploy Application button in the Deploying Applications page.
  15. Click Open in Browser to display the app in Runtime Manager.

    If CloudHub displays a permissions error, select a different environment to deploy to.

You have successfully used Studio 6 to configure a Mule 3 app with an object store. Next, you test the connection by submitting REST API commands to the Object Store API and using Runtime Manager to view the results.

Test Your Studio 6 Application

After you create your app in Studio 6, you can test it by using a curl command to submit a REST API command to the Object Store API and use Runtime Manager to view the results.

To test your app:

  1. In Runtime Manager, click Applications and ensure that the osv2-demo-studio-6 app is running.

  2. Click the Status column for the osv2-demo-studio-6 app to display its details in the right pane.

  3. Copy the App url value:

    App url in Runtime Manager
    Figure 46. The arrow shows App url in the details pane in Runtime Manager.
  4. From the command line, run the following curl command, replacing APP-URL with the App url value that you copied from Runtime Manager:

    $ curl -X POST -H "Content-Type: application/json" -d '{ "key": "myStudio6Key", "value": "OSv2 Test from Studio 6" }' "http://APP-URL/store";echo

    The output from this command displays the key-value pair that you sent to the object store:

    KEY: myStudio6Key AND VALUE: OSv2 Test from Studio 6 WERE SAVED

    Each time you submit this command, change the key name so that each key is unique.

  5. In Runtime Manager, click Manage application in the details pane for the application:

    Manage application in the details pane
    Figure 47. The arrow shows Manage application in the details pane in Runtime Manager.
  6. Click Object Store in the left navigation pane.

  7. Click the object store, the partition, and then the key:

    Object Store tab
    Figure 48. The screenshot shows (1) the Object Store tab, (2) the key, and (3) the value in the object store.
  8. Hover over the …​ icon to display actions for each object:

    os tutorial rtm os actions 3
    Figure 49. The screenshot shows (1) the Metadata and (2) the Delete Value actions in the object store.
    • To delete an object store, partition, key, or value, hover over the …​ icon and click the trash can icon.

    • To display the key value and any metadata associated with the value, hover over the …​ icon and click the metadata icon.

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub