Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: run state and sequencer quickstart with java sdk #683

Merged
merged 7 commits into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 54 additions & 2 deletions docs/en/start/sequencer/start.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,13 @@ Once finished, the layotto file will be generated in the directory, run it:
```shell @background
./layotto start -c ../../configs/runtime_config.json
```

<!-- tabs:end -->

### step 2. Run the client program and call Layotto to generate a unique id
<!-- tabs:start -->
#### **Go**
Build and run the golang demo:

```shell
cd ${project_path}/demo/sequencer/common/
Expand All @@ -86,6 +90,54 @@ Next id:next_id:10
Demo success!
```

#### **Java**

Download java sdk and examples:

```shell @if.not.exist java-sdk
git clone https://github.com/layotto/java-sdk
```

```shell
cd java-sdk
```

Build and run the demo:

```shell
# build example jar
mvn -f examples-sequencer/pom.xml clean package
# run the example
java -jar examples-sequencer/target/examples-sequencer-1.1.0-jar-with-dependencies.jar
```

If the following information is printed, the demo is successful:

```bash
Try to get next id.Key: examples
Next id: 1
Try to get next id.Key: examples
Next id: 2
Try to get next id.Key: examples
Next id: 3
Try to get next id.Key: examples
Next id: 4
Try to get next id.Key: examples
Next id: 5
Try to get next id.Key: examples
Next id: 6
Try to get next id.Key: examples
Next id: 7
Try to get next id.Key: examples
Next id: 8
Try to get next id.Key: examples
Next id: 9
Try to get next id.Key: examples
Next id: 10
```

<!-- tabs:end -->

### step 3. Stop containers and release resources
<!-- tabs:start -->
#### **Docker Compose**
Expand All @@ -107,9 +159,9 @@ docker rm -f etcd

### Next step
#### What does this client program do?
The demo client program uses the golang version SDK provided by Layotto, calls the Layotto Sequencer API, and generates a distributed unique, self-increasing id.
The demo client program uses the SDK provided by Layotto, calls the Layotto Sequencer API, and generates a distributed unique, self-increasing id.

The sdk is located in the `sdk` directory, and users can call the API provided by Layotto through the sdk.
The golang sdk is located in the `sdk` directory, and the java sdk is in https://github.com/layotto/java-sdk

In addition to using sdk, you can also interact with Layotto directly through grpc in any language you like.

Expand Down
38 changes: 38 additions & 0 deletions docs/en/start/state/start.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ The layotto file will be generated in the directory, run it:
<!-- tabs:end -->

### step 2. Run the client program, call Layotto to add, delete, modify and query
<!-- tabs:start -->
#### **Go**

Build and run the golang demo:

```shell
# open a new terminal tab
Expand All @@ -109,6 +113,40 @@ DeleteState succeeded.key:key1
DeleteState succeeded.key:key2
```

#### **Java**

Download java sdk and examples:

```shell @if.not.exist java-sdk
git clone https://github.com/layotto/java-sdk
```

```shell
cd java-sdk
```

Build and run it:

```shell
# build example jar
mvn -f examples-state/pom.xml clean package
# run the example
java -jar examples-state/target/examples-state-1.1.0-jar-with-dependencies.jar
```

The demo will print the following message:

```bash
SaveState succeeded.key:key1 , value: v11
GetState succeeded. key:key1 value:v11
DeleteState succeeded. key:key1
GetState after delete. key:key1 value:
SaveBulkState succeeded. key:key1 , key2
GetBulkState succeeded. key:key2
```

<!-- tabs:end -->

### step 3. Stop containers and release resources
<!-- tabs:start -->
#### **Docker Compose**
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/start/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

在开始之前,您需要在电脑上准备以下环境:

- Golang 1.14及以上
- Golang 1.14及以上, **或者** Java 8 、Maven 3
- Docker

如果您准备好了,可以点击左侧导航栏里的各种 Demo,开始我们的旅行!
Expand Down
61 changes: 58 additions & 3 deletions docs/zh/start/sequencer/start.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,14 @@ go build -o layotto
```shell @background
./layotto start -c ../../configs/runtime_config.json
```

<!-- tabs:end -->

### step 2. 运行客户端程序,调用Layotto生成唯一id
<!-- tabs:start -->
#### **Go**

构建、运行 go 语言 demo:

```shell
cd ${project_path}/demo/sequencer/common/
Expand All @@ -89,6 +94,56 @@ Next id:next_id:10
Demo success!
```

#### **Java**

Download java sdk and examples:

```shell @if.not.exist java-sdk
git clone https://github.com/layotto/java-sdk
```

切换目录:

```shell
cd java-sdk
```

构建、运行:

```shell
# build example jar
mvn -f examples-sequencer/pom.xml clean package
# run the example
java -jar examples-sequencer/target/examples-sequencer-1.1.0-jar-with-dependencies.jar
```

打印出以下信息说明运行成功:

```bash
Try to get next id.Key: examples
Next id: 1
Try to get next id.Key: examples
Next id: 2
Try to get next id.Key: examples
Next id: 3
Try to get next id.Key: examples
Next id: 4
Try to get next id.Key: examples
Next id: 5
Try to get next id.Key: examples
Next id: 6
Try to get next id.Key: examples
Next id: 7
Try to get next id.Key: examples
Next id: 8
Try to get next id.Key: examples
Next id: 9
Try to get next id.Key: examples
Next id: 10
```

<!-- tabs:end -->

### step 3.销毁容器,释放资源
<!-- tabs:start -->
#### **关闭 Docker Compose**
Expand All @@ -110,11 +165,11 @@ docker rm -f etcd

### 下一步
#### 这个客户端程序做了什么?
示例客户端程序中使用了Layotto提供的golang版本sdk,调用Layotto Sequencer API,生成分布式唯一、自增id。
示例客户端程序中使用了Layotto提供的多语言 sdk,调用Layotto Sequencer API,生成分布式唯一、自增id。

sdk位于`sdk`目录下,用户可以通过sdk调用Layotto提供的API。
go sdk位于`sdk`目录下,java sdk 在 https://github.com/layotto/java-sdk

除了使用sdk,您也可以用任何您喜欢的语言、通过grpc直接和Layotto交互。
除了使用sdk调用Layotto提供的API,您也可以用任何您喜欢的语言、通过grpc直接和Layotto交互。

其实sdk只是对grpc很薄的封装,用sdk约等于直接用grpc调。

Expand Down
41 changes: 41 additions & 0 deletions docs/zh/start/state/start.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,14 @@ go build -o layotto
```shell @background
./layotto start -c ../../configs/config_redis.json
```

<!-- tabs:end -->

### step 2. 运行客户端程序,调用Layotto进行增删改查
<!-- tabs:start -->
#### **Go**

构建、运行 go 语言 demo:

```shell
# open a new terminal tab
Expand All @@ -108,6 +113,42 @@ DeleteState succeeded.key:key1
DeleteState succeeded.key:key2
```

#### **Java**

Download java sdk and examples:

```shell @if.not.exist java-sdk
git clone https://github.com/layotto/java-sdk
```

切换目录:

```shell
cd java-sdk
```

构建、运行:

```shell
# build example jar
mvn -f examples-state/pom.xml clean package
# run the example
java -jar examples-state/target/examples-state-1.1.0-jar-with-dependencies.jar
```

打印出以下信息说明运行成功:

```bash
SaveState succeeded.key:key1 , value: v11
GetState succeeded. key:key1 value:v11
DeleteState succeeded. key:key1
GetState after delete. key:key1 value:
SaveBulkState succeeded. key:key1 , key2
GetBulkState succeeded. key:key2
```

<!-- tabs:end -->

### step 3. 销毁容器,释放资源
<!-- tabs:start -->
#### **关闭 Docker Compose**
Expand Down