Contact Free trial Login

Tutorial: Object Store v2

This document helps you use Object Store v2 to store and view data.

Prerequisites

This document assumes you are familiar with Anypoint Studio, using curl from a command line, and the use of Anypoint Platform and Runtime Manager. Ensure that curl is installed on your computer. If you are using a Mac or Linux, the curl command is built in. For Windows, download and install curl. Alternatively, you can use Postman or browser plugins instead of curl.

You also need to have a Design environment configured in Anypoint Platform Access Management > Environments. If you don’t see Access Management, contact your site administrator.

Install the Object Store Connector

  1. In Anypoint Studio, click the Exchange icon in the Studio task bar.

  2. Click Login in Anypoint Exchange.

  3. Search for the objectstore connector and click Install.

  4. Follow the prompts to install the connector.

Create a Design Center Application

Disable password programs such as LastPass or Okta in your browser before using Design Center. Otherwise, these programs inserts passwords in the HTTP Listener’s TLS tab. The passwords in the TLS tab cause your application’s deployment to fail.

In the Design Center section of the tutorial, you can create an application consisting of an HTTP Listener trigger and an Object Store Connector component. Then you can use the command line to send a key and value, and view the key in Runtime Manager.

Configure and Run an Application

  1. In Anypoint Platform, click Design Center > Create > Mule Application.

  2. Specify a Project Name such as osv2.

  3. In the Let’s Get Started wizard, click Go straight to canvas.

  4. For the Trigger, select HTTP Listener:

    os dc http trigger
  5. Specify the Path as /store.

  6. Click Edit:

    os dc http edit
  7. Click Save. You can use the default settings.

    os dc http settings
  8. Click the plus sign to the right of the trigger:

    os dc plus sign
  9. In the Select a component window, search for Obj, then click ObjectStore Connector, and click the Store operation.

    os dc os store op
  10. Specify the Key as #[payload.key] and the Value with the payload.value string.

    os dc store setup
  11. Click the Run button at the top of the Design Center window. When successful, Running appears.

    os dc run button
  12. To the right of the Run button are three vertical dots. Click the dots, then click Copy link.

This completes creating the first part of your application. Leave your Design Center application running for the next task where we test the application. Even if the Design Center window times out, the application stays running while you are logged on. Click the application in the Projects screen and look for Status Running.

Test the Design Center Application

  1. Open a command line and enter this command:

    curl -X POST -H "Content-Type: application/json" -d '{ "key": "MyKey", "value": "OSv2 Test" }' "http://LINK_FROM_DESIGN_CENTER/store"
  2. Substitute LINK_FROM_DESIGN_CENTER with the link you copied from Design Center, and then press Enter to send the command to Design Center.

    The output is an echo:

    { "key": "MyKey", "value": "OSv2 Test" }
  3. In Anypoint Platform, click the menu icon in the upper left and click Runtime Manager.

  4. Notice how an entry has been created for you in the list of applications.

  5. Click CloudHub in the Server column for your application to display details, and click Manage Application.

    os rm manage app
  6. Click Object Store and click the object store, then the partition, and the key. You can see the value as [binary value] BINARY.

MyKey is in the Object Store user interface, which confirms that the key can be sent through your Design Center application and stored in the Object Store.

The value is binary because Mule 4 wraps values in a Mule object that causes them to be only visible in binary through Anypoint Platform. Behind the scenes, Mule 4 executes binary serialization with the Mule internal serializer. The user interface cannot deserialize the object, hence it can only tell you that the value is now binary in the user interface.

To verify that your value worked too, return to Design Center and add a new flow that retrieves a value.

Retrieve the Value

  1. Click the menu icon and click Design Center.

  2. In Design Center, click your project, and click Open.

  3. Open the rectangular box icon to the left of Project to expand the Flow menu.

  4. First rename your existing flow by clicking the vertical dot icon and clicking Rename from the menu. Change New Flow to Store.

    os dc flows
  5. Click the plus sign to the right of Flows.

  6. Click Go straight to canvas to exit the wizard.

  7. In the Trigger menu, choose HTTP Listener.

  8. For Path, specify the /retrieve value.

    os dc http retrieve

    Because the default settings for the HTTP Listener are correct, there’s no need to click Edit. However you can verify that Host is 0.0.0.0 and Port is 8081. These values are the same as in the previous Store flow.

  9. Now that we have started the flow, rename it to Retrieve.

  10. Click the plus sign next to the HTTP Listener to add a component.

  11. In Select a component, search for Obj, and click the ObjectStore Connector.

  12. Click the Retrieve operation and in the Key field, specify the #[attributes.queryParams.key] value.

This completes the Retrieve flow. Click Run again to restart your application.

In the command prompt, submit a curl command to view the key’s value:

curl http://LINK_FROM_DESIGN_CENTER/retrieve?key=MyKey;echo

Replace LINK_FROM_DESIGN_CENTER with the cloudhub.io link in Design Center.

(The ;echo statement at the end of the command makes the output more readable.)

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

"OSv2 Test"

This exercise shows that the object store you create in Design Center can be accessed using a curl command, and the key becomes visible in Runtime Manager.

You don’t need to view the Runtime Manager interface each time you update an object store. After you create an application linked to the Object Store v2 connector, you can store a key and value in the Object Store with one curl command and view the results with another. Just change the key and/or the value as needed.

Store:

curl -X POST -H "Content-Type: application/json" -d '{ "key": "MyKey", "value": "OSv2 Test" }' "http://LINK_FROM_DESIGN_CENTER/store"

Retrieve:

curl http://LINK_FROM_DESIGN_CENTER/retrieve?key=MyKey

In each command, replace LINK_FROM_DESIGN_CENTER with the cloudhub.io link in Design Center.

For more information on moving to programmatic access of Object Store, see Object Store API docs. Programmatic conventions that worked with Object Store v1 also work with Object Store v2.

Create a Studio 7 Project

  1. In Anypoint Studio, click File > New > Mule Project and give the project a name such as osv2.

  2. Click the Exchange X icon in the upper left of the Studio task bar.

  3. In the Exchange window, click Login and provide your Anypoint Platform user name and password.

  4. Search for the ObjectStore Connector for Mule 4. You can enter a substring such as "obj" and Exchange finds the right asset for you.

  5. Click the ObjectStore Connector for Mule 4 Exchange asset, and click Add to project in the upper right. Click Proceed at the verification prompt.

  6. In the Studio Mule Palette, click HTTP. Click Listener and drag it to the canvas.

    os as drag listener
  7. Click the green plus sign to the right of the Connector configuration field and set the Host to 0.0.0.0 and the Port to 8081.

    os as http listener config
  8. In the connector’s main screen, set Path to /store.

    os as http path
  9. Click ObjectStore in the Mule Palette and drag the Store operation to the canvas.

  10. Specify the Key as #[payload.key] and the Value with the payload.value string.

  11. Click the green plus sign to the right of the Object Store field, and in the Global Element Properties screen, click OK to accept the defaults.

  12. Click the HTTP Listener again and drag it to the canvas under the first flow to create a second flow. Use the same settings as in Step 7. In the main screen, set Path to retrieve.

    os as 2nd flow http
  13. Click ObjectStore in the Mule Palette and drag the Retrieve operation to the canvas.

  14. Set the Key field to #[attributes.queryParams.key].

  15. Click the green plus sign to the right of the Object Store field, and in the Global Element Properties screen, click OK to accept the defaults.

  16. You can change a flow label by double-clicking it. Change the first flow to Store and the second flow to Retrieve.

    When done, the flows should appear as:

    os as finished flows

You now have a completed Studio application. You can test that it runs correctly by clicking Run As > Mule Application. This is just a test. Once you get your application to run, you can stop it.

Test Your Studio 7 Application

  1. In Studio, right click your project in the Package Explorer.

  2. Click Anypoint Platform > Deploy to CloudHub. Note: CloudHub is name of the server, but you access your application in Anypoint Platform Runtime Manager.

    os as deploy to cloudhub
  3. After your application appears in Anypoint Platform Runtime Manager, start it so that the application is running. Note the cloudhub.io URL.

  4. From the command line, enter this curl command:

    $ curl -X POST -H "Content-Type: application/json" -d '{ "key": "MyKey", "value": "OSv2 Test" }' "http://LINK_FROM_RUNTIME_MANAGER/store"

    Replace LINK_FROM_RUNTIME_MANAGER with the cloudhub.io URL for your application in Runtime Manager.

    You can improve readability for this command if you append ;echo to the end of the command.

  5. In Runtime Manager, click CloudHub in the Server column for your application to display details, and click Manage Application.

    os rm manage app
  6. Click Object Store and choose the object store, the partition, and key you wish to view. You can see the value as [binary value] BINARY.

    You can see that MyKey made it into the Object Store v2 user interface, confirming that keys can be sent through your Design Center application and stored in the Object Store.

  7. To view the value for the key, use this curl command:

    curl http://LINK_FROM_RUNTIME_MANAGER/retrieve?key=MyKey

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

    "OSv2 Test"

This concludes the Studio 7 exercise. The gist of this lesson is that you can create Object Store flows in Studio, use the curl command to store key/value pairs in the Object Store, and view the results in Runtime Manager. An additional curl command lets you see the value for a key.

Studio 7 XML

The XML for the Studio application is as follows. This information lets you see how Studio identifies the HTTP Listener and Object Store connector in XML. You can also use this to check your flow if your Studio project doesn’t work as expected. (Your project’s XML file contains doc ID statements, which are not listed here to improve readability.)

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

<mule xmlns:os="http://www.mulesoft.org/schema/mule/os"
	xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
	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/ee/core
http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.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">
		<http:listener-connection host="0.0.0.0" port="8081" />
	</http:listener-config>
	<os:object-store name="Object_store" doc:name="Object store" />
	<http:listener-config name="HTTP_Listener_config1"
		doc:name="HTTP Listener config">
		<http:listener-connection host="0.0.0.0" port="8081" />
	</http:listener-config>
	<os:object-store name="Object_store1" doc:name="Object store" />
	<flow name="Store" >
		<http:listener doc:name="Listener" config-ref="HTTP_Listener_config"
			path="/store">
			<ee:repeatable-file-store-stream />
		</http:listener>
		<os:store doc:name="Store"
			key="#[payload.key]"
			objectStore="Object_store">
			<os:value ><![CDATA[payload.value]]></os:value>
		</os:store>
	</flow>
	<flow name="Retrieve" >
		<http:listener doc:name="Listener" config-ref="HTTP_Listener_config1"
			path="/retrieve">
			<ee:repeatable-file-store-stream />
		</http:listener>
		<os:retrieve doc:name="Retrieve"
			key="#[attributes.queryParams.key]"
			objectStore="Object_store1"/>
	</flow>
</mule>

Create a Studio 6 Project

If you are only working in Anypoint Studio 7, skip this section.

  1. To create a new project, open Anypoint Studio and click File > New > Mule Project. In this tutorial, the project name is objstoredemo.

  2. Create an application like this:

    osv2 studio flow
  3. Search for http and drag and drop the HTTP connector onto the Studio Canvas. The HTTP connector listens for the curl command we use to store a key and value in Object Store.

    Click the green plus to the right of Connector Configuration and in the Global Element Properties screen, accpet the default settings (Host 0.0.0.0 and Port 8081), and click OK:

    osv2 http config
  4. In the HTTP properties screen, set Path to /store and Allowed Methods to POST:

    osv2 http properties

    When you submit a curl command, use the /store option in the URL, for example, objstoredemo.cloudhub.io/store. The Allowed Methods setting ensures that those who use the curl command can POST information only to an object store.

  5. Locate and add the Object to String component to the Studio canvas. No settings are necessary — this component converts the content received from the HTTP connector into a string.

  6. Locate and add the JSON to Object component. Set the Return Class to java.util.Map:

    osv2 json to object
  7. Search for objectstore and add the Object Store connector. If there is no Object Store connector, install it as described in Install the Object Store Connector.

  8. Click the green plus sign to the right of Connector Configuration and in the Global Element Properties screen, assign a Partition name such as mypartition. Set the Object Store Reference field to _defaultUserObjectStore.

    Note: The Object Store Reference field must be set to _defaultUserObjectStore for data to be stored in Object Store v2:

    Studio Global Element Property settings

    Leave the remaining settings blank, and click OK.

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

    • Set Key to #[payload.key]

    • Set Value Reference to #[payload.value]

    osv2 connector
  10. Locate and add Set Payload. Set the Value field to KEY: #[payload.key] AND VALUE: #[payload.value] WERE SAVED OK - this message displays on the command line to let you know the curl command values are received by the application.

    osv2 set payload
  11. Save the application and click Run > Run As > Mule Application. Running the application ensures your application works correctly. If you need to fix anything, do so now. After your application runs correctly, you can stop your application.

To Deploy Your Application in Anypoint Platform

  1. In Studio, right-click your application’s name in Package Explorer and click Anypoint Platform > Deploy to Cloud.

  2. In the user login window, specify your Anypoint Platform username and password, and click Sign in. If you don’t have an Anypoint Platform login, click Sign up.

  3. In Runtime Manager, specify an application name. Each name is unique and becomes the URL where your application is available in Runtime Manager. The URL has the format APPLICATION_NAME.cloudhub.io where your application resides in the cloudhub.io namespace. Ensure the application name has a green check mark for proper naming and being unique.

    If you see the message: You do not have permission to deploy new applications in this environment. Please select an existing application to redeploy, click the environment button in the upper left of the Runtime Manager display to change environments from Design to Production.

  4. Set Runtime Version to Mule 3.8.5 or later, or to any 4.x version. Ensure that Runtime Manager shows the Use Object Store v2 checkbox.

  5. Click the Use Object Store v2 checkbox.

    osv2-runtime_manager_deploy_app
  6. After configuring your application, click Deploy Application.

  7. In the Runtime Manager deploy window, wait until a message displays that your application successfully deployed to CloudHub.

  8. Click Open in Browser and Close Window.

  9. In Runtime Manager, click the right side of your application’s entry to view its details.

  10. Click Manage Application. In the application’s settings screen, note that Object Store appears in the left side navigation area. The former label Application Data is now Object Store for OSv2.

Send Data to the Object Store

From a command line prompt, use a utility to send JSON data to your Mule application. This can be a command such as curl, Postman, or a browser extension. Any serializable data can be sent to the object store. The Object Store connector sends data as key/value pairs.

Example using curl:

curl -X POST -H "Content-Type: application/json" -d '{ "key": "TestKey01", "value": "This is an object store test" }' "http://APPLICATION_NAME.cloudhub.io/store"

Change APPLICATION_NAME to the name you chose when you deployed your application. Each time you submit this command, change the key’s name so that each key is unique.

View Data in the Object Store

To view data in the Object Store:

  1. Log into Anypoint Platform and click Runtime Manager.

  2. Click the name of your application to view the application’s dashboard.

  3. Click Object Store from the left navigation bar:

    osv2 in nav bar

    The Object Store user interface:

    osv2 ui
    • The default object store name is DEFAULT_USER_STORE.

    • The columns show the object store name, partition name, key, and key data. The partition groups object store keys.

  4. Click the object store name, partition name, and key to view each item’s value.

  5. To delete a key, hover over a key name, and click the trash can icon. Similarly, you can delete a partition or the store itself by hovering and clicking the trash can icon.

Note: Object Store v2 provides persistent storage of objects with a time to live (TTL) of up to 30 days.

We use cookies to make interactions with our websites and services easy and meaningful, to better understand how they are used and to tailor advertising. You can read more and make your cookie choices here. By continuing to use this site you are giving us your consent to do this.