Skip to content

Commit

Permalink
docs: add a specific usage example
Browse files Browse the repository at this point in the history
Signed-off-by: zhiheng123 <[email protected]>
  • Loading branch information
zhiheng123 committed Sep 3, 2024
1 parent 0182f33 commit 81ef711
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CONTRIBUTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

Coming soon...
63 changes: 61 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -58,3 +58,62 @@ docker run -p 8086:8086 --name opengemini --rm opengeminidb/opengemini-server
<version>${latest.version}</version>
</dependency>
```

## 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<Void> createdb = openGeminiJdkClient.createDatabase(databaseName);
createdb.get();

Point point = new Point();
point.setMeasurement("ms_quick_start");
HashMap<String, String> tags = new HashMap<>();
HashMap<String, Object> 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<QueryResult> queryRst = openGeminiJdkClient.query(selectQuery);

System.out.println("query result: " + queryRst.get());
}
}
```

## Contributor

Welcome to [join us](Contribution.md)
62 changes: 60 additions & 2 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ OpenGemini 是一款云原生分布式时序数据库。获取更多信息,请
| opengemini-client-kotlin/scala | - | 对应开发语言的首选 | 敬请期待 |


## 要求
## 依赖

- 编译本项目至少需要OpenJDK 17
- 运行本项目时,各组件依赖的jdk版本不同,如上个章节表格中所示


## 用法
## 集成

### 构建

Expand All @@ -59,3 +59,61 @@ docker run -p 8086:8086 --name opengemini --rm opengeminidb/opengemini-server
<version>${latest.version}</version>
</dependency>
```

## 快速上手

```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<Void> createdb = openGeminiJdkClient.createDatabase(databaseName);
createdb.get();

Point point = new Point();
point.setMeasurement("ms_quick_start");
HashMap<String, String> tags = new HashMap<>();
HashMap<String, Object> 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<QueryResult> queryRst = openGeminiJdkClient.query(selectQuery);

System.out.println("query result: " + queryRst.get());
}
}
```
## 贡献

欢迎[加入我们](Contribution.md)

0 comments on commit 81ef711

Please sign in to comment.