Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
5ecf860f
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
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看板
提交
5ecf860f
编写于
9月 01, 2022
作者:
D
dingbo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test: subscribe with rust
上级
00ac9049
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
18 addition
and
12 deletion
+18
-12
docs/examples/rust/cloud-example/Cargo.toml
docs/examples/rust/cloud-example/Cargo.toml
+4
-0
docs/examples/rust/cloud-example/examples/subscribe_demo.rs
docs/examples/rust/cloud-example/examples/subscribe_demo.rs
+14
-12
未找到文件。
docs/examples/rust/cloud-example/Cargo.toml
浏览文件 @
5ecf860f
...
...
@@ -7,3 +7,7 @@ edition = "2021"
taos
=
{
version
=
"*"
,
default-features
=
false
,
features
=
["ws"]
}
tokio
=
{
version
=
"1"
,
features
=
["full"]
}
anyhow
=
"1.0.0"
serde
=
{
version
=
"1"
,
features
=
["derive"]
}
chrono
=
"*"
pretty_env_logger
=
"0.4"
log
=
"*"
docs/examples/rust/cloud-example/examples/subscribe_demo.rs
浏览文件 @
5ecf860f
...
...
@@ -18,6 +18,7 @@ struct Record {
async
fn
prepare
(
taos
:
Taos
)
->
anyhow
::
Result
<
()
>
{
let
inserted
=
taos
.exec_many
([
"use tmq"
,
// create child table
"CREATE TABLE `d0` USING `meters` TAGS(0, 'Los Angles')"
,
// insert into child table
...
...
@@ -35,22 +36,20 @@ async fn prepare(taos: Taos) -> anyhow::Result<()> {
#[tokio::main]
async
fn
main
()
->
anyhow
::
Result
<
()
>
{
let
mut
dsn
=
std
::
env
::
var
(
"TDENGINE_CLOUD_DSN"
)
.parse
()
?
;
let
builder
=
TaosBuilder
::
from_dsn
(
dsn
)
?
;
std
::
env
::
set_var
(
"RUST_LOG"
,
"debug"
);
pretty_env_logger
::
init
();
let
dsn
=
std
::
env
::
var
(
"TDENGINE_CLOUD_DSN"
)
?
;
let
builder
=
TaosBuilder
::
from_dsn
(
&
dsn
)
?
;
let
taos
=
builder
.build
()
?
;
let
db
=
"tmq"
;
// prepare database
taos
.exec_many
([
format!
(
"DROP TOPIC IF EXISTS tmq_meters"
),
format!
(
"DROP DATABASE IF EXISTS `{db}`"
),
format!
(
"CREATE DATABASE `{db}`"
),
format!
(
"USE `{db}`"
),
// create super table
format!
(
"CREATE TABLE `meters` (`ts` TIMESTAMP, `current` FLOAT, `voltage` INT, `phase` FLOAT) TAGS (`groupid` INT, `location` BINARY(16))"
),
// create topic for subscription
format!
(
"CREATE TOPIC tmq_meters with META AS DATABASE {db}"
)
"DROP TOPIC IF EXISTS tmq_meters"
,
"USE tmq"
,
"CREATE STABLE IF NOT EXISTS `meters` (`ts` TIMESTAMP, `current` FLOAT, `voltage` INT, `phase` FLOAT) TAGS (`groupid` INT, `location` BINARY(16))"
,
"CREATE TOPIC tmq_meters with META AS DATABASE tmq"
])
.await
?
;
...
...
@@ -59,10 +58,13 @@ async fn main() -> anyhow::Result<()> {
tokio
::
time
::
sleep
(
Duration
::
from_secs
(
1
))
.await
;
// subscribe
let
tmq
=
TmqBuilder
::
from_dsn
(
"taosws://localhost:6030/?group.id=test"
)
?
;
let
dsn2
=
format!
(
"{dsn}&group.id=test"
);
dbg!
(
&
dsn2
);
let
tmq
=
TmqBuilder
::
from_dsn
(
dsn2
)
?
;
let
mut
consumer
=
tmq
.build
()
?
;
consumer
.subscribe
([
"tmq_meters"
])
.await
?
;
println!
(
"start subscription"
);
{
let
mut
stream
=
consumer
.stream
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录