From 81ef711ab16c17df43d90f698be33f4a5cab1165 Mon Sep 17 00:00:00 2001
From: zhiheng123 <903292776@qq.com>
Date: Sat, 31 Aug 2024 18:02:05 +0800
Subject: [PATCH] docs: add a specific usage example
Signed-off-by: zhiheng123 <903292776@qq.com>
---
CONTRIBUTION.md | 2 ++
README.md | 63 +++++++++++++++++++++++++++++++++++++++++++++++--
README_CN.md | 62 ++++++++++++++++++++++++++++++++++++++++++++++--
3 files changed, 123 insertions(+), 4 deletions(-)
create mode 100644 CONTRIBUTION.md
diff --git a/CONTRIBUTION.md b/CONTRIBUTION.md
new file mode 100644
index 00000000..ff5a0072
--- /dev/null
+++ b/CONTRIBUTION.md
@@ -0,0 +1,2 @@
+
+Coming soon...
diff --git a/README.md b/README.md
index cf31baea..a73c1686 100644
--- a/README.md
+++ b/README.md
@@ -28,12 +28,12 @@ OpenGemini is a cloud-native distributed time series database, find more informa
| opengemini-client-kotlin/scala | - | Preferred for Corresponding Development Language | Stay Tuned |
-## Requirements
+## Prerequisites
- Compiling this project requires at least OpenJDK 17
- When running this project, the OpenJDK versions depended on by various components are different, as shown in the table in the previous chapter
-## Usage
+## Integration
### Build
@@ -58,3 +58,62 @@ docker run -p 8086:8086 --name opengemini --rm opengeminidb/opengemini-server
${latest.version}
```
+
+## Quick Start
+
+```java
+package org.example;
+
+import io.opengemini.client.api.Address;
+import io.opengemini.client.api.Point;
+import io.opengemini.client.api.Query;
+import io.opengemini.client.api.QueryResult;
+import io.opengemini.client.jdk.Configuration;
+import io.opengemini.client.jdk.OpenGeminiJdkClient;
+
+import java.time.Duration;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+
+public class Main {
+
+ public static void main(String[] args) throws ExecutionException, InterruptedException {
+ Configuration configuration = Configuration.builder()
+ .addresses(Collections.singletonList(new Address("127.0.0.1", 8086)))
+ .connectTimeout(Duration.ofSeconds(3))
+ .timeout(Duration.ofSeconds(5))
+ .build();
+
+ OpenGeminiJdkClient openGeminiJdkClient = new OpenGeminiJdkClient(configuration);
+
+ String databaseName = "db_quick_start";
+ CompletableFuture createdb = openGeminiJdkClient.createDatabase(databaseName);
+ createdb.get();
+
+ Point point = new Point();
+ point.setMeasurement("ms_quick_start");
+ HashMap tags = new HashMap<>();
+ HashMap fields = new HashMap<>();
+ tags.put("tag1", "tag value1");
+ fields.put("field1", "field value1");
+ point.setTags(tags);
+ point.setFields(fields);
+
+ openGeminiJdkClient.write(databaseName, point).get();
+
+ // Creating a new tag requires waiting for the server to create and update indexes
+ Thread.sleep(3000);
+
+ Query selectQuery = new Query("select * from " + "ms_quick_start", databaseName, "");
+ CompletableFuture queryRst = openGeminiJdkClient.query(selectQuery);
+
+ System.out.println("query result: " + queryRst.get());
+ }
+}
+```
+
+## Contributor
+
+Welcome to [join us](Contribution.md)
diff --git a/README_CN.md b/README_CN.md
index 4c785563..58e09984 100644
--- a/README_CN.md
+++ b/README_CN.md
@@ -28,13 +28,13 @@ OpenGemini 是一款云原生分布式时序数据库。获取更多信息,请
| opengemini-client-kotlin/scala | - | 对应开发语言的首选 | 敬请期待 |
-## 要求
+## 依赖
- 编译本项目至少需要OpenJDK 17
- 运行本项目时,各组件依赖的jdk版本不同,如上个章节表格中所示
-## 用法
+## 集成
### 构建
@@ -59,3 +59,61 @@ docker run -p 8086:8086 --name opengemini --rm opengeminidb/opengemini-server
${latest.version}
```
+
+## 快速上手
+
+```java
+package org.example;
+
+import io.opengemini.client.api.Address;
+import io.opengemini.client.api.Point;
+import io.opengemini.client.api.Query;
+import io.opengemini.client.api.QueryResult;
+import io.opengemini.client.jdk.Configuration;
+import io.opengemini.client.jdk.OpenGeminiJdkClient;
+
+import java.time.Duration;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+
+public class Main {
+
+ public static void main(String[] args) throws ExecutionException, InterruptedException {
+ Configuration configuration = Configuration.builder()
+ .addresses(Collections.singletonList(new Address("127.0.0.1", 8086)))
+ .connectTimeout(Duration.ofSeconds(3))
+ .timeout(Duration.ofSeconds(5))
+ .build();
+
+ OpenGeminiJdkClient openGeminiJdkClient = new OpenGeminiJdkClient(configuration);
+
+ String databaseName = "db_quick_start";
+ CompletableFuture createdb = openGeminiJdkClient.createDatabase(databaseName);
+ createdb.get();
+
+ Point point = new Point();
+ point.setMeasurement("ms_quick_start");
+ HashMap tags = new HashMap<>();
+ HashMap fields = new HashMap<>();
+ tags.put("tag1", "tag value1");
+ fields.put("field1", "field value1");
+ point.setTags(tags);
+ point.setFields(fields);
+
+ openGeminiJdkClient.write(databaseName, point).get();
+
+ // Creating a new tag requires waiting for the server to create and update indexes
+ Thread.sleep(3000);
+
+ Query selectQuery = new Query("select * from " + "ms_quick_start", databaseName, "");
+ CompletableFuture queryRst = openGeminiJdkClient.query(selectQuery);
+
+ System.out.println("query result: " + queryRst.get());
+ }
+}
+```
+## 贡献
+
+欢迎[加入我们](Contribution.md)