From 8c6ff828e913e2c2eeef766a9c31b15146cd7b1b Mon Sep 17 00:00:00 2001
From: sheyanjie-qq <249478495@qq.com>
Date: Fri, 2 Aug 2024 17:06:40 +0800
Subject: [PATCH] mod rust example
---
.../nativeexample/examples/subscribe_demo.rs | 48 +++++++-
.../restexample/examples/subscribe_demo.rs | 4 +-
docs/zh/08-develop/01-connect/index.md | 82 -------------
docs/zh/08-develop/02-sql.md | 21 +---
docs/zh/08-develop/04-schemaless.md | 12 --
docs/zh/08-develop/05-stmt.md | 13 ---
docs/zh/08-develop/07-tmq.md | 110 +-----------------
7 files changed, 56 insertions(+), 234 deletions(-)
diff --git a/docs/examples/rust/nativeexample/examples/subscribe_demo.rs b/docs/examples/rust/nativeexample/examples/subscribe_demo.rs
index d54bb60e93..8486419386 100644
--- a/docs/examples/rust/nativeexample/examples/subscribe_demo.rs
+++ b/docs/examples/rust/nativeexample/examples/subscribe_demo.rs
@@ -38,7 +38,7 @@ async fn main() -> anyhow::Result<()> {
let dsn = "taos://localhost:6030";
let builder = TaosBuilder::from_dsn(dsn)?;
- let taos = builder.build()?;
+ let taos = builder.build().await?;
let db = "tmq";
// prepare database
@@ -61,9 +61,10 @@ async fn main() -> anyhow::Result<()> {
// subscribe
let tmq = TmqBuilder::from_dsn("taos://localhost:6030/?group.id=test")?;
- let mut consumer = tmq.build()?;
+ let mut consumer = tmq.build().await?;
consumer.subscribe(["tmq_meters"]).await?;
+ // ANCHOR: consumer_commit_manually
consumer
.stream()
.try_for_each(|(offset, message)| async {
@@ -78,11 +79,54 @@ async fn main() -> anyhow::Result<()> {
println!("** read {} records: {:#?}\n", records.len(), records);
}
}
+ // commit offset manually when you have processed the message.
consumer.commit(offset).await?;
Ok(())
})
.await?;
+ // ANCHOR_END: consumer_commit_manually
+
+ // ANCHOR: assignments
+ let assignments = consumer.assignments().await.unwrap();
+ log::info!("assignments: {:?}", assignments);
+ // ANCHOR_END: assignments
+
+ // seek offset
+ for topic_vec_assignment in assignments {
+ let topic = &topic_vec_assignment.0;
+ let vec_assignment = topic_vec_assignment.1;
+ for assignment in vec_assignment {
+ let vgroup_id = assignment.vgroup_id();
+ let current = assignment.current_offset();
+ let begin = assignment.begin();
+ let end = assignment.end();
+ log::debug!(
+ "topic: {}, vgroup_id: {}, current offset: {} begin {}, end: {}",
+ topic,
+ vgroup_id,
+ current,
+ begin,
+ end
+ );
+ // ANCHOR: seek_offset
+ let res = consumer.offset_seek(topic, vgroup_id, end).await;
+ if res.is_err() {
+ log::error!("seek offset error: {:?}", res);
+ let a = consumer.assignments().await.unwrap();
+ log::error!("assignments: {:?}", a);
+ }
+ // ANCHOR_END: seek_offset
+ }
+
+ let topic_assignment = consumer.topic_assignment(topic).await;
+ log::debug!("topic assignment: {:?}", topic_assignment);
+ }
+
+ // after seek offset
+ let assignments = consumer.assignments().await.unwrap();
+ log::info!("after seek offset assignments: {:?}", assignments);
+
consumer.unsubscribe().await;
task.await??;
diff --git a/docs/examples/rust/restexample/examples/subscribe_demo.rs b/docs/examples/rust/restexample/examples/subscribe_demo.rs
index 8486419386..2e95fb0543 100644
--- a/docs/examples/rust/restexample/examples/subscribe_demo.rs
+++ b/docs/examples/rust/restexample/examples/subscribe_demo.rs
@@ -35,7 +35,7 @@ async fn prepare(taos: Taos) -> anyhow::Result<()> {
#[tokio::main]
async fn main() -> anyhow::Result<()> {
- let dsn = "taos://localhost:6030";
+ let dsn = "ws://localhost:6041";
let builder = TaosBuilder::from_dsn(dsn)?;
let taos = builder.build().await?;
@@ -59,7 +59,7 @@ async fn main() -> anyhow::Result<()> {
tokio::time::sleep(Duration::from_secs(1)).await;
// subscribe
- let tmq = TmqBuilder::from_dsn("taos://localhost:6030/?group.id=test")?;
+ let tmq = TmqBuilder::from_dsn("ws://localhost:6041/?group.id=test")?;
let mut consumer = tmq.build().await?;
consumer.subscribe(["tmq_meters"]).await?;
diff --git a/docs/zh/08-develop/01-connect/index.md b/docs/zh/08-develop/01-connect/index.md
index 21d11df23c..0e92400d9e 100644
--- a/docs/zh/08-develop/01-connect/index.md
+++ b/docs/zh/08-develop/01-connect/index.md
@@ -13,8 +13,6 @@ import ConnNode from "./_connect_node.mdx";
import ConnPythonNative from "./_connect_python.mdx";
import ConnCSNative from "./_connect_cs.mdx";
import ConnC from "./_connect_c.mdx";
-import ConnR from "./_connect_r.mdx";
-import ConnPHP from "./_connect_php.mdx";
import InstallOnLinux from "../../14-reference/05-connector/_linux_install.mdx";
import InstallOnWindows from "../../14-reference/05-connector/_windows_install.mdx";
import InstallOnMacOS from "../../14-reference/05-connector/_macos_install.mdx";
@@ -249,62 +247,12 @@ dotnet add package TDengine.Connector
:::
-
-
-
-1. 下载 [taos-jdbcdriver-version-dist.jar](https://repo1.maven.org/maven2/com/taosdata/jdbc/taos-jdbcdriver/3.0.0/)。
-2. 安装 R 的依赖包`RJDBC`:
-
-```R
-install.packages("RJDBC")
-```
-
如果已经安装了 TDengine 服务端软件或 TDengine 客户端驱动 taosc, 那么已经安装了 C 连接器,无需额外操作。
-
-
-
-**下载代码并解压:**
-
-```shell
-curl -L -o php-tdengine.tar.gz https://github.com/Yurunsoft/php-tdengine/archive/refs/tags/v1.0.2.tar.gz \
-&& mkdir php-tdengine \
-&& tar -xzf php-tdengine.tar.gz -C php-tdengine --strip-components=1
-```
-
-> 版本 `v1.0.2` 只是示例,可替换为任意更新的版本,可在 [TDengine PHP Connector 发布历史](https://github.com/Yurunsoft/php-tdengine/releases) 中查看可用版本。
-
-**非 Swoole 环境:**
-
-```shell
-phpize && ./configure && make -j && make install
-```
-
-**手动指定 TDengine 目录:**
-
-```shell
-phpize && ./configure --with-tdengine-dir=/usr/local/Cellar/tdengine/3.0.0.0 && make -j && make install
-```
-
-> `--with-tdengine-dir=` 后跟上 TDengine 目录。
-> 适用于默认找不到的情况,或者 macOS 系统用户。
-
-**Swoole 环境:**
-
-```shell
-phpize && ./configure --enable-swoole && make -j && make install
-```
-
-**启用扩展:**
-
-方法一:在 `php.ini` 中加入 `extension=tdengine`
-
-方法二:运行带参数 `php -d extension=tdengine test.php`
-
@@ -404,8 +352,6 @@ DSN 的详细说明和如何使用详见 [连接功能](../../reference/connecto
- `reconnectRetryCount`:重连次数,默认为 3。
- `reconnectIntervalMs`:重连间隔毫秒时间,默认为 2000。
-
-
使用客户端驱动访问 TDengine 集群的基本过程为:建立连接、查询和写入、关闭连接、清除资源。
@@ -433,10 +379,6 @@ DSN 的详细说明和如何使用详见 [连接功能](../../reference/connecto
:::
-
-
-
-
@@ -475,15 +417,9 @@ DSN 的详细说明和如何使用详见 [连接功能](../../reference/connecto
{{#include docs/examples/csharp/wsConnect/Program.cs:main}}
```
-
-
-
-
-
-
### 原生连接
@@ -513,15 +449,9 @@ DSN 的详细说明和如何使用详见 [连接功能](../../reference/connecto
{{#include docs/examples/csharp/connect/Program.cs:main}}
```
-
-
-
-
-
-
@@ -550,15 +480,9 @@ DSN 的详细说明和如何使用详见 [连接功能](../../reference/connecto
不支持
-
-
-
-
-
-
@@ -642,14 +566,8 @@ let taos = pool.get()?;
不支持
-
-
-
-
-
-
diff --git a/docs/zh/08-develop/02-sql.md b/docs/zh/08-develop/02-sql.md
index 8871dee786..01d94cca53 100644
--- a/docs/zh/08-develop/02-sql.md
+++ b/docs/zh/08-develop/02-sql.md
@@ -13,9 +13,8 @@ TDengine 对 SQL 语言提供了全面的支持,允许用户以熟悉的 SQL
:::note
-REST 连接:各编程语言的连接器封装使用 `HTTP` 请求的连接,支持数据写入和查询操作。
-
-REST API:通过 `curl` 命令进行数据写入和查询操作。
+REST 连接:各编程语言的连接器封装使用 `HTTP` 请求的连接,支持数据写入和查询操作,开发者依然使用连接器提供的接口访问 `TDengine`。
+REST API:直接调用 `taosadapter` 提供的 REST API 接口,进行数据写入和查询操作。代码示例使用 `curl` 命令来演示。
:::
@@ -68,16 +67,12 @@ REST API:通过 `curl` 命令进行数据写入和查询操作。
{{#include docs/examples/csharp/wsInsert/Program.cs:create_db_and_table}}
```
-
-
```c
{{#include docs/examples/c/CCreateDBDemo.c:create_db_and_table}}
```
> **注意**:如果不使用 `USE power` 指定数据库,则后续对表的操作都需要增加数据库名称作为前缀,如 power.meters。
-
-
创建数据库
@@ -149,8 +144,6 @@ NOW 为系统内部函数,默认为客户端所在计算机当前时间。 NOW
{{#include docs/examples/csharp/wsInsert/Program.cs:insert_data}}
```
-
-
```c
{{#include docs/examples/c/CInsertDataDemo.c:insert_data}}
@@ -159,8 +152,6 @@ NOW 为系统内部函数,默认为客户端所在计算机当前时间。 NOW
**Note**
NOW 为系统内部函数,默认为客户端所在计算机当前时间。 NOW + 1s 代表客户端当前时间往后加 1 秒,数字后面代表时间单位:a(毫秒),s(秒),m(分),h(小时),d(天),w(周),n(月),y(年)。
-
-
写入数据
@@ -222,15 +213,11 @@ curl --location -uroot:taosdata 'http://127.0.0.1:6041/rest/sql' \
{{#include docs/examples/csharp/wsInsert/Program.cs:select_data}}
```
-
-
```c
{{#include docs/examples/c/CQueryDataDemo.c:query_data}}
```
-
-
查询数据
@@ -288,15 +275,11 @@ reqId 可用于请求链路追踪,reqId 就像分布式系统中的 traceId
{{#include docs/examples/csharp/wsInsert/Program.cs:query_id}}
```
-
-
```c
{{#include docs/examples/c/CWithReqIdDemo.c:with_reqid}}
```
-
-
查询数据,指定 reqId 为 3
diff --git a/docs/zh/08-develop/04-schemaless.md b/docs/zh/08-develop/04-schemaless.md
index 611878960d..5d376222e7 100644
--- a/docs/zh/08-develop/04-schemaless.md
+++ b/docs/zh/08-develop/04-schemaless.md
@@ -200,12 +200,8 @@ writer.write(lineDemo, SchemalessProtocolType.LINE, SchemalessTimestampType.NANO
{{#include docs/examples/csharp/wssml/Program.cs:main}}
```
-
-
-
-
### 原生连接
@@ -234,12 +230,8 @@ writer.write(lineDemo, SchemalessProtocolType.LINE, SchemalessTimestampType.NANO
{{#include docs/examples/csharp/nativesml/Program.cs:main}}
```
-
-
-
-
@@ -262,12 +254,8 @@ writer.write(lineDemo, SchemalessProtocolType.LINE, SchemalessTimestampType.NANO
不支持
-
-
-
-
diff --git a/docs/zh/08-develop/05-stmt.md b/docs/zh/08-develop/05-stmt.md
index d3e71eed63..f60e7b1705 100644
--- a/docs/zh/08-develop/05-stmt.md
+++ b/docs/zh/08-develop/05-stmt.md
@@ -60,15 +60,9 @@ import TabItem from "@theme/TabItem";
```csharp
{{#include docs/examples/csharp/wsStmt/Program.cs:main}}
```
-
-
-
-
-
-
@@ -98,15 +92,8 @@ import TabItem from "@theme/TabItem";
```csharp
{{#include docs/examples/csharp/stmtInsert/Program.cs:main}}
```
-
-
-
-
-
-
-
diff --git a/docs/zh/08-develop/07-tmq.md b/docs/zh/08-develop/07-tmq.md
index d2b759bfd7..ff7ac5d997 100644
--- a/docs/zh/08-develop/07-tmq.md
+++ b/docs/zh/08-develop/07-tmq.md
@@ -90,15 +90,9 @@ Rust 连接器创建消费者的参数为 DSN, 可以设置的参数列表请
其他参数见上表。
-
-
-
-
-
-
@@ -153,16 +147,8 @@ Rust 连接器创建消费者的参数为 DSN, 可以设置的参数列表请
```
-
-
-
-
-
-
-
-
@@ -212,17 +198,10 @@ Rust 连接器创建消费者的参数为 DSN, 可以设置的参数列表请
```
-
-
-
-
-
-
-
## 订阅消费数据
@@ -276,16 +255,8 @@ TMQ 消息队列是一个 [futures::Stream](https://docs.rs/futures/latest/futur
```
-
-
-
-
-
-
-
-
@@ -320,17 +291,10 @@ TMQ 消息队列是一个 [futures::Stream](https://docs.rs/futures/latest/futur
```
-
-
-
-
-
-
-
## 指定订阅的 Offset
@@ -390,17 +354,10 @@ TMQ 消息队列是一个 [futures::Stream](https://docs.rs/futures/latest/futur
```
-
-
-
-
-
-
-
### 原生连接
@@ -434,16 +391,8 @@ TMQ 消息队列是一个 [futures::Stream](https://docs.rs/futures/latest/futur
```
-
-
-
-
-
-
-
-
@@ -499,18 +448,9 @@ TMQ 消息队列是一个 [futures::Stream](https://docs.rs/futures/latest/futur
```
-
-
-
-
-
-
-
-
-
### 原生连接
@@ -549,18 +489,9 @@ TMQ 消息队列是一个 [futures::Stream](https://docs.rs/futures/latest/futur
```
-
-
-
-
-
-
-
-
-
@@ -611,18 +542,10 @@ TMQ 消息队列是一个 [futures::Stream](https://docs.rs/futures/latest/futur
```
-
-
-
-
-
-
-
-
### 原生连接
@@ -660,18 +583,10 @@ TMQ 消息队列是一个 [futures::Stream](https://docs.rs/futures/latest/futur
```
-
-
-
-
-
-
-
-
@@ -703,7 +618,9 @@ TMQ 消息队列是一个 [futures::Stream](https://docs.rs/futures/latest/futur
-
+```rust
+{{#include docs/examples/rust/restexample/examples/subscribe_demo.rs}}
+```
@@ -719,18 +636,10 @@ TMQ 消息队列是一个 [futures::Stream](https://docs.rs/futures/latest/futur
```
-
-
-
-
-
-
-
-
### 原生连接
@@ -763,7 +672,9 @@ TMQ 消息队列是一个 [futures::Stream](https://docs.rs/futures/latest/futur
-
+```rust
+{{#include docs/examples/rust/nativeexample/examples/subscribe_demo.rs}}
+```
@@ -776,16 +687,7 @@ TMQ 消息队列是一个 [futures::Stream](https://docs.rs/futures/latest/futur
```
-
-
-
-
-
-
-
-
-