-
Studio 7
-
Studio 6
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:
-
Configure Anypoint Connector for Object Store (Object Store Connector) in the app.
-
Send data to the object store.
-
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
-
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 testingThis 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:
-
In Anypoint Platform, click Design Center in the left navigation bar or the main Anypoint Platform screen.
-
Click Create new > Create new application:
Figure 1. The arrow shows the Create new application option. -
In the New Mule Application window, enter
osv2demo
for the project name and click Create. -
In the wizard, click Go straight to canvas:
Figure 2. The arrow shows the Go straight to canvas option. -
Click Trigger and enter
H
to search for HTTP Listener:Figure 3. The arrow shows HTTP Listener. -
Click HTTP Listener.
-
In the HTTP Listener window, set the value of Path to
/store
and then click the 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.
-
Click the plus icon (+) to the right of the HTTP Listener trigger:
Figure 5. The arrow shows the plus icon (+). -
In the Select a component window, enter
ob
to search for ObjectStore Connector:Figure 6. The arrow shows ObjectStore Connector. -
Click the connector and then click the Store operation:
Figure 7. The arrow shows the Store operation. -
In the Configuration tab, specify
#[payload.key]
in the Key field andpayload.value
in the Value field:Figure 8. The screenshot shows (1) the Key field and (2) the Value field.The maximum size for a key is 1024 bytes (UTF-8 encoding).
Object Store v2 doesn’t support using pipe (
|
) characters in keys. -
Click Test to run the app in a temporary location.
The app starts running in a temporary environment:
Figure 9. The arrow shows a message indicating theosv2demo
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:
-
Click the copy icon to copy the deployment URL:
Figure 10. The arrow shows the deployment URL copy icon. -
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" }
-
Select View in Runtime Manager from the … menu in the right corner:
Figure 11. The arrow shows the … menu and View in Runtime Manager option in Design Center. -
In Runtime Manager, click Object Store in the left navigation pane.
-
Click the object store, the partition, and then the key:
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 fromcurl
appears in the object store with the value of[binary value] BINARY
.The
myKey
key that you sent fromcurl
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:
-
In Design Center, in the Project area on the left, expand the Flows menu.
-
Select Rename from the vertical ellipsis menu and rename your existing flow from
New Flow
toStore
:Figure 13. The screenshot shows (1) the vertical ellipsis menu and (2) the Rename option. -
Click the plus sign to the right of Flows.
-
In the wizard, click Go straight to canvas:
Figure 14. The arrow shows the Go straight to canvas option. -
Click the Trigger box and enter
H
to search for HTTP Listener:Figure 15. The arrow shows the HTTP Listener. -
Click HTTP Listener.
-
In the HTTP Listener window, set the value of Path to
/retrieve
and then click the 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.
-
Rename this new flow to
Retrieve
. -
Click the plus icon (+) to the right of the HTTP Listener trigger to add Object Store Connector.
-
In the Select a component window, enter
ob
to search for ObjectStore Connector:Figure 17. The arrow shows ObjectStore Connector. -
Click the connector and then click the Retrieve operation.
-
In the Configuration tab, specify
#[attributes.queryParams.key]
in the Key field:Figure 18. The arrow shows the Key field in the Retrieve configuration. -
Click Test to run the app in a temporary location.
-
Click the copy icon to copy the deployment URL:
Figure 19. The arrow shows the deployment URL copy icon. -
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:
-
Start Studio, click File > New > Mule Project, name the project
osv2-demo
, and then click Finish. -
Install Object Store Connector:
-
Click the Exchange icon in the toolbar:
Figure 20. The arrow shows the Exchange icon in the Studio 7 toolbar. -
Enter your Anypoint Platform username and password, if prompted.
-
In Exchange, select Provided by MuleSoft and then search for ObjectStore Connector:
Figure 21. The screenshot shows (1) the Provided by MuleSoft option and (2) the search field. -
Select ObjectStore Connector - Mule 4.
-
Click Add to project:
Figure 22. The arrow shows the Add to project icon in Exchange. -
At the confirmation prompt, click Proceed and then click OK.
-
-
In the Mule Palette view, click HTTP, and then drag Listener to the Studio canvas:
Figure 23. The screenshot shows (1) HTTP Connector and (2) the Listener operation. -
Click ObjectStore and then drag the Store operation to the right of Listener on the canvas.
Figure 24. The arrow shows the Store operation in the Studio 7 canvas. -
In the canvas, click Listener.
-
In the Listener properties window, set General > Path to
/store
. -
Click the green plus icon (+) to the right of the Connector configuration field.
-
In the HTTP Listener Global Element Properties window, verify that Host is set to
0.0.0.0
and Port is set to8081
, and then click OK.The Listener properties window indicates that there are no errors:
Figure 25. The screenshot shows (1) the Path property and (2) the Connector configuration icon for the Listener operation. -
In the canvas, click the Store operation.
-
In the Store properties window, specify
#[payload.key]
in the Key field andpayload.value
in the Value field: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.
Object Store v2 doesn’t support using pipe (
|
) characters in keys. -
Select the flow and, in the properties window, change the name to
Store
:Figure 27. The arrow shows the Name field in the Store flow properties window. -
In the Mule Palette view, click HTTP and then drag another Listener to the canvas below the first flow.
-
Click ObjectStore and then drag the Retrieve operation to the right of Listener in the second flow.
-
In the canvas, click Listener.
-
In the Listener properties window, set General > Path to
/retrieve
. -
In the Connector configuration menu, select the same HTTP_Listener_config option that you set up for the Listener operation in the Store flow:
Figure 28. The arrow shows the Connector configuration menu in the Listener properties window. -
In the canvas, click the Retrieve operation.
-
In the Retrieve properties window, specify
#[attributes.queryParams.key]
in the Key field:Figure 29. The arrow shows the Key field in the Retrieve properties window. -
Select the second flow and, in the properties window, change the name to
Retrieve
.When you are done, the flows should look similar to this:
Figure 30. The screenshot shows (1) the Store flow and (2) the Retrieve flow. -
In Package Explorer in Studio, right-click
osv2-demo
and select Anypoint Platform > Deploy to CloudHub. -
At the prompt, select the environment to deploy the app to.
-
In the Anypoint Platform Deploying Application window, click Deploy Application:
Figure 31. The arrow shows the Deploy Application button in the Deploying Application page. -
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:
-
In Runtime Manager, click Applications and ensure that the
osv2-demo
app is running. -
Click the Status column for the
osv2-demo
app to display its details in the right pane. -
Copy the App url value:
Figure 32. The arrow shows App url in the details pane in Runtime Manager. -
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" }
-
In Runtime Manager, click Manage application in the details pane for the application:
Figure 33. The arrow shows Manage application in the details pane in Runtime Manager. -
Click Object Store in the left navigation pane.
-
Click the object store, the partition, and then the key:
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 fromcurl
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. -
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>
<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: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:
-
Start Studio, click File > New > Mule Project, name the project
osv2-demo-studio-6
, and then click Finish. -
Install Object Store Connector:
-
Click the Exchange icon in the toolbar:
Figure 35. The arrow shows the Exchange icon in the Studio 6 toolbar. -
Enter your Anypoint Platform username and password, if prompted.
-
In Exchange, select Provided by MuleSoft and then search for ObjectStore Connector:
Figure 36. The screenshot shows (1) the Provided by MuleSoft option and (2) the search field. -
Select Object Store Connector - Mule 3.
-
Click Install:
Figure 37. The arrow shows the Install icon in Exchange. -
At the prompt, check the items to install and click Next twice.
-
Accept the license agreement and click Finish.
-
At the prompt, click Restart Now to finish installing the connector.
-
-
In the Mule Palette view:
-
Drag HTTP to the Studio canvas:
Figure 38. The arrow shows HTTP Connector. -
Search for
string
and then drag Object to String to the Process area to the right of HTTP on the canvas. -
Search for
json
and then drag JSON to Object to the canvas to the right of Object to String. -
Search for
objects
and then drag ObjectStore to the canvas to the right of JSON to Object. -
Search for
payload
and then drag Set Payload to the canvas to the right of ObjectStore.The flow should look like this:
Figure 39. The arrow shows the flow in the canvas.
-
-
In the canvas, click HTTP.
-
In the HTTP properties window:
-
Set Path to
/store
and Allowed Methods toPOST
.When you submit a curl command, you append the
/store
option to the URL. The Allowed Methods setting ensures that thecurl
command can only POST information to the object store. -
Click the green plus icon (+) to the right of Connector Configuration.
-
In the HTTP Connector Global Element Properties window, verify that Host is set to
0.0.0.0
and Port is set to8081
, and then click OK.The HTTP properties window now indicates that there are no errors:
Figure 40. The arrow shows the HTTP properties window.
-
-
In the canvas, click JSON to Object and then set Return Class to
java.util.Map
:Figure 41. The arrow shows the Return Class field in the JSON to Object properties window. -
In the canvas, click ObjectStore.
-
In the ObjectStore properties window:
-
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.
Object Store v2 doesn’t support using pipe (
|
) characters in keys. -
Set Value Reference to
#[payload.value]
.
-
-
Click the green plus icon (+) to the right of Connector Configuration.
-
In the ObjectStore Connector Global Element Properties window, set Partition to
myPartition
and Object Store Reference to_defaultUserObjectStore
, and then click OK.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:
Figure 43. The arrow shows the ObjectStore properties window.
-
-
In the canvas, click Set Payload.
-
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:Figure 44. The arrow shows the Value field in the Set Payload properties window. -
Save your project.
-
In Package Explorer in Studio, right-click
osv2-demo-studio-6
and select Anypoint Platform > Deploy to Cloud. -
At the prompt, select the environment to deploy the app to.
-
In the Anypoint Platform Deploying Application window, ensure that Use Object Store v2 is selected and then click Deploy Application:
Figure 45. The arrow shows the Deploy Application button in the Deploying Applications page. -
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:
-
In Runtime Manager, click Applications and ensure that the
osv2-demo-studio-6
app is running. -
Click the Status column for the
osv2-demo-studio-6
app to display its details in the right pane. -
Copy the App url value:
Figure 46. The arrow shows App url in the details pane in Runtime Manager. -
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.
-
In Runtime Manager, click Manage application in the details pane for the application:
Figure 47. The arrow shows Manage application in the details pane in Runtime Manager. -
Click Object Store in the left navigation pane.
-
Click the object store, the partition, and then the key:
Figure 48. The screenshot shows (1) the Object Store tab, (2) the key, and (3) the value in the object store. -
Hover over the … icon to display actions for each object:
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.
-