Java SDK Data Import
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 https://repo1.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 in the GitHub repository td-logger-java.
YOUR_API_KEY
should be your actual apikey string. You can retrieve your API key from the TD Console.
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 TD Console.
From CLI
Issue the td tables
command if you have the TD Toolbelt CLI.
$ td tables
+------------+------------+------+-----------+
| Database | Table | Type | Count |
+------------+------------+------+-----------+
| production | follow | log | 1 |
+------------+------------+------+-----------+