Nav

Anypoint Object Store v2 Tutorial - Beta

This document helps you understand the use of the Object Store v2 (OSv2) user interface and the OSv2 connector, and how to send data to object store.

Prerequisites

Tutorial Summary

osv2-overview

  1. Create an application in Anypoint Studio that contains the Object Store connector.

  2. Deploy the application from Studio to Runtime Manager.

  3. Start the application in Runtime Manager.

  4. Use a program such as curl or Postman to write data to the object store.

  5. View the object store data in Runtime Manager.

Configuring Object Store Access

  1. Open Anypoint Studio.

  2. Click the Anypoint Exchange icon in the Studio taskbar:

    osv2-exchange-x

  3. When the Exchange window opens, install the Object Store connector.

Create an Object Store Application in Anypoint Studio

Create an Anypoint Studio application:

  1. Open Anypoint Studio and create a new project using 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. The HTTP connector listens for the HTTP packet that we will send using a curl command.

    Click the green plus to the right of Connector Configuration and in the Global Element Properties screen, take 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 we submit our curl command to send a URL to Anypoint Platform, we use the /store option in our URL, for example, objectstoredemo.cloudhub.io/store. The Allowed Methods setting ensures that those using our curl command can only POST information to the object store. For more information about the curl command and equivalent commands for Windows, see Sending Data to the Object Store.

    In the current Object Store Beta release, information can be posted to the object store, but you can only view the data using the Object Store user interface.
  5. Locate and add Object to String. No settings are necessary — this component translates the content received from the HTTP connector to a string.

  6. Locate and add JSON to Object. 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 Configuring Object Store Access.

    1. Click the green plus sign to the right of Connector Configuration and in the Global Element Properties screen, leave all the settings blank, and click OK.

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

      • Key to #[payload.key]

      • Value Reference to #[payload.value]

        osv2-connector

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

  9. 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 use the Console to stop your application.

Deploy an Application in Anypoint Platform

You can deploy an application in the current CloudHub Object Store. After you try this, you can use the information that follows to test Object Store version 2.

To deploy your application:

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

  2. At 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:

    • Give the application a name. Each name is unique and becomes the URL under which your application is stored in Runtime Manager. The URL is in the form <application_name>.cloudhub.io. Ensure the application name gets a green checkmark for proper naming and being unique.

    • Set the Runtime version.

    • Click the Use Object Store v2 checkbox.

      osv2-runtime_manager_deploy_app

  4. After configuring your application, click Deploy Application.

  5. Runtime Manager prompts you to ensure you want to make this choice.

  6. Start your application.

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

If you use Windows, you can get an add-on curl command from:

For other operating systems, curl.haxx.se supports dozens more systems. In addition, you can get curl add-ins for the Chrome browser.

Mac/Linux command line:

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.

Viewing 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 appears as follows:

    osv2-ui

    In the current Beta release:

    • The Object Store name is DEFAULT_USER_STORE.

    • The time to live (TTL) value is set at 14 days (1209600 seconds).

  4. Click the Object Store name. You can click a key name to view its value.

  5. You can delete keys by clicking the Key down arrow symbol:

    osv2-delete-keys