Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
abf3204b
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
abf3204b
编写于
11月 18, 2022
作者:
S
Shengliang Guan
提交者:
GitHub
11月 18, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #18257 from taosdata/docs/TD-20499-rust-tmq-demo
docs: update tmq demo
上级
a12cf7f9
83815bc0
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
15 addition
and
23 deletion
+15
-23
docs/examples/rust/nativeexample/Cargo.toml
docs/examples/rust/nativeexample/Cargo.toml
+1
-1
docs/examples/rust/nativeexample/examples/stmt_example.rs
docs/examples/rust/nativeexample/examples/stmt_example.rs
+6
-3
docs/examples/rust/nativeexample/examples/subscribe_demo.rs
docs/examples/rust/nativeexample/examples/subscribe_demo.rs
+8
-18
docs/examples/rust/restexample/examples/insert_example.rs
docs/examples/rust/restexample/examples/insert_example.rs
+0
-1
未找到文件。
docs/examples/rust/nativeexample/Cargo.toml
浏览文件 @
abf3204b
...
...
@@ -10,4 +10,4 @@ chrono = "0.4"
serde
=
{
version
=
"1"
,
features
=
["derive"]
}
tokio
=
{
version
=
"1"
,
features
=
[
"rt"
,
"macros"
,
"rt-multi-thread"
]
}
taos
=
{
version
=
"0.
*
"
}
taos
=
{
version
=
"0.
4.8
"
}
docs/examples/rust/nativeexample/examples/stmt_example.rs
浏览文件 @
abf3204b
...
...
@@ -12,7 +12,10 @@ async fn main() -> anyhow::Result<()> {
// bind table name and tags
stmt
.set_tbname_tags
(
"d1001"
,
&
[
Value
::
VarChar
(
"California.SanFransico"
.into
()),
Value
::
Int
(
2
)],
&
[
Value
::
VarChar
(
"California.SanFransico"
.into
()),
Value
::
Int
(
2
),
],
)
?
;
// bind values.
let
values
=
vec!
[
...
...
docs/examples/rust/nativeexample/examples/subscribe_demo.rs
浏览文件 @
abf3204b
...
...
@@ -50,7 +50,7 @@ async fn main() -> anyhow::Result<()> {
// create super table
format!
(
"CREATE TABLE `meters` (`ts` TIMESTAMP, `current` FLOAT, `voltage` INT, `phase` FLOAT) TAGS (`groupid` INT, `location` BINARY(24))"
),
// create topic for subscription
format!
(
"CREATE TOPIC tmq_meters
with META AS DATABASE {db}
"
)
format!
(
"CREATE TOPIC tmq_meters
AS SELECT * FROM `meters`
"
)
])
.await
?
;
...
...
@@ -64,13 +64,9 @@ async fn main() -> anyhow::Result<()> {
let
mut
consumer
=
tmq
.build
()
?
;
consumer
.subscribe
([
"tmq_meters"
])
.await
?
;
{
let
mut
stream
=
consumer
.stream
();
while
let
Some
((
offset
,
message
))
=
stream
.try_next
()
.await
?
{
// get information from offset
// the topic
consumer
.stream
()
.try_for_each
(|(
offset
,
message
)|
async
{
let
topic
=
offset
.topic
();
// the vgroup id, like partition id in kafka.
let
vgroup_id
=
offset
.vgroup_id
();
...
...
@@ -78,20 +74,14 @@ async fn main() -> anyhow::Result<()> {
if
let
Some
(
data
)
=
message
.into_data
()
{
while
let
Some
(
block
)
=
data
.fetch_raw_block
()
.await
?
{
// one block for one table, get table name if needed
let
name
=
block
.table_name
();
let
records
:
Vec
<
Record
>
=
block
.deserialize
()
.try_collect
()
?
;
println!
(
"** table: {}, got {} records: {:#?}
\n
"
,
name
.unwrap
(),
records
.len
(),
records
);
println!
(
"** read {} records: {:#?}
\n
"
,
records
.len
(),
records
);
}
}
consumer
.commit
(
offset
)
.await
?
;
}
}
Ok
(())
})
.await
?
;
consumer
.unsubscribe
()
.await
;
...
...
docs/examples/rust/restexample/examples/insert_example.rs
浏览文件 @
abf3204b
...
...
@@ -5,7 +5,6 @@ async fn main() -> anyhow::Result<()> {
let
dsn
=
"ws://"
;
let
taos
=
TaosBuilder
::
from_dsn
(
dsn
)
?
.build
()
?
;
taos
.exec_many
([
"DROP DATABASE IF EXISTS power"
,
"CREATE DATABASE power"
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录