You can import the data from your Java applications, using Treasure Data’s Java SDK.


Prerequisites

  • Basic knowledge of Java.

  • Basic knowledge of Maven2.

  • Basic knowledge of Treasure Data.

  • Java 6 or higher (for local testing).

Install ‘td-logger-java’ Library

Add the following lines to your pom.xml. Replace myVersion with your version. The logger library’s version information can be found in CHANGES.txt.

<dependencies>
  ...
  <dependency>
    <groupId>com.treasuredata</groupId>
    <artifactId>td-logger</artifactId>
    <version>myVersion</version>
  </dependency>
  ...
</dependencies>

If you need an all-in-one jar file, we provide one at http://central.maven.org/maven2/com/treasuredata/.

Modify Your App

The td-logger-java library comes with a built-in library for recording in-app events. Insert the following code to record events from your app. Further details regarding the event logger API can be found here.

YOUR_API_KEY should be your actual apikey string. You can retrieve your API key from HERE.

import com.treasure_data.logger.TreasureDataLogger;
public class Main {
  private static TreasureDataLogger LOG;
  static {
    try {
      Properties props = System.getProperties();
      props.load(Main.class.getClassLoader().getResourceAsStream("treasure-data.properties"));
      LOG = TreasureDataLogger.getLogger("production");
    } catch (IOException e) {
      // do something
    }
  }
  public void doApp() {
    Map<String, Object> data = new HashMap<String, Object>();
    data.put("from", "userA");
    data.put("to", "userB");
    LOG.log("follow", data);
  }
}

Your event-logging code should be placed near its corresponding event-generating code.

When using the td-logger-java library, the posted records are buffered in the memory locally at first, and the data is uploaded every 5 minutes. Because a dedicated thread uploads the data into the cloud, it doesn’t affect your application’s response time.

The local buffer also has a size limit. If the local data exceeds this limit, the records will be uploaded immediately.

Confirming Data Import

The data gets uploaded every 5 minutes. You can confirm the data import from TD Console or CLI.

From TD Console

To confirm that your data has been uploaded successfully, check your dataset from the Console.

From CLI

Or, use td tables if you have the CLI.

$ td tables
+------------+------------+------+-----------+
| Database   | Table      | Type | Count     |
+------------+------------+------+-----------+
| production | follow     | log  | 1         |
+------------+------------+------+-----------+
  • No labels