Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
4063cfbc
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看板
未验证
提交
4063cfbc
编写于
4月 24, 2023
作者:
H
Haojun Liao
提交者:
GitHub
4月 24, 2023
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #21053 from taosdata/feature/3_liaohj
refactor: do some internal refactor and add the sample code.
上级
6386c323
e21fa9fd
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
39 addition
and
10 deletion
+39
-10
examples/c/tmq.c
examples/c/tmq.c
+31
-2
include/client/taos.h
include/client/taos.h
+2
-2
source/client/src/clientTmq.c
source/client/src/clientTmq.c
+5
-5
source/client/test/clientTests.cpp
source/client/test/clientTests.cpp
+1
-1
未找到文件。
examples/c/tmq.c
浏览文件 @
4063cfbc
...
...
@@ -20,7 +20,8 @@
#include <time.h>
#include "taos.h"
static
int
running
=
1
;
static
int
running
=
1
;
const
char
*
topic_name
=
"topicname"
;
static
int32_t
msg_process
(
TAOS_RES
*
msg
)
{
char
buf
[
1024
];
...
...
@@ -243,7 +244,7 @@ _end:
tmq_list_t
*
build_topic_list
()
{
tmq_list_t
*
topicList
=
tmq_list_new
();
int32_t
code
=
tmq_list_append
(
topicList
,
"topicname"
);
int32_t
code
=
tmq_list_append
(
topicList
,
topic_name
);
if
(
code
)
{
tmq_list_destroy
(
topicList
);
return
NULL
;
...
...
@@ -269,6 +270,31 @@ void basic_consume_loop(tmq_t* tmq) {
fprintf
(
stderr
,
"%d msg consumed, include %d rows
\n
"
,
msgCnt
,
totalRows
);
}
void
consume_repeatly
(
tmq_t
*
tmq
)
{
int32_t
numOfAssignment
=
0
;
tmq_topic_assignment
*
pAssign
=
NULL
;
int32_t
code
=
tmq_get_topic_assignment
(
tmq
,
topic_name
,
&
pAssign
,
&
numOfAssignment
);
if
(
code
!=
0
)
{
fprintf
(
stderr
,
"failed to get assignment, reason:%s"
,
tmq_err2str
(
code
));
}
// seek to the earliest offset
for
(
int32_t
i
=
0
;
i
<
numOfAssignment
;
++
i
)
{
tmq_topic_assignment
*
p
=
&
pAssign
[
i
];
code
=
tmq_offset_seek
(
tmq
,
topic_name
,
p
->
vgId
,
p
->
begin
);
if
(
code
!=
0
)
{
fprintf
(
stderr
,
"failed to seek to %ld, reason:%s"
,
p
->
begin
,
tmq_err2str
(
code
));
}
}
free
(
pAssign
);
// let's do it again
basic_consume_loop
(
tmq
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
int32_t
code
;
...
...
@@ -294,10 +320,13 @@ int main(int argc, char* argv[]) {
if
((
code
=
tmq_subscribe
(
tmq
,
topic_list
)))
{
fprintf
(
stderr
,
"Failed to tmq_subscribe(): %s
\n
"
,
tmq_err2str
(
code
));
}
tmq_list_destroy
(
topic_list
);
basic_consume_loop
(
tmq
);
consume_repeatly
(
tmq
);
code
=
tmq_consumer_close
(
tmq
);
if
(
code
)
{
fprintf
(
stderr
,
"Failed to close consumer: %s
\n
"
,
tmq_err2str
(
code
));
...
...
include/client/taos.h
浏览文件 @
4063cfbc
...
...
@@ -263,7 +263,7 @@ DLL_EXPORT const char *tmq_err2str(int32_t code);
/* ------------------------TMQ CONSUMER INTERFACE------------------------ */
typedef
struct
tmq_topic_assignment
{
int32_t
vg
roupHandle
;
int32_t
vg
Id
;
int64_t
currentOffset
;
int64_t
begin
;
int64_t
end
;
...
...
@@ -277,7 +277,7 @@ DLL_EXPORT int32_t tmq_consumer_close(tmq_t *tmq);
DLL_EXPORT
int32_t
tmq_commit_sync
(
tmq_t
*
tmq
,
const
TAOS_RES
*
msg
);
DLL_EXPORT
void
tmq_commit_async
(
tmq_t
*
tmq
,
const
TAOS_RES
*
msg
,
tmq_commit_cb
*
cb
,
void
*
param
);
DLL_EXPORT
int32_t
tmq_get_topic_assignment
(
tmq_t
*
tmq
,
const
char
*
pTopicName
,
tmq_topic_assignment
**
assignment
,
int32_t
*
numOfAssignment
);
DLL_EXPORT
int32_t
tmq_offset_seek
(
tmq_t
*
tmq
,
const
char
*
pTopicName
,
int32_t
vg
roupHandle
,
int64_t
offset
);
DLL_EXPORT
int32_t
tmq_offset_seek
(
tmq_t
*
tmq
,
const
char
*
pTopicName
,
int32_t
vg
Id
,
int64_t
offset
);
/* ----------------------TMQ CONFIGURATION INTERFACE---------------------- */
...
...
source/client/src/clientTmq.c
浏览文件 @
4063cfbc
...
...
@@ -2357,7 +2357,7 @@ static int32_t tmqGetWalInfoCb(void* param, SDataBuf* pMsg, int32_t code) {
tmq_topic_assignment
assignment
=
{.
begin
=
pHead
->
walsver
,
.
end
=
pHead
->
walever
,
.
currentOffset
=
rsp
.
rspOffset
.
version
,
.
vg
roupHandle
=
pParam
->
vgId
};
.
vg
Id
=
pParam
->
vgId
};
taosThreadMutexLock
(
&
pCommon
->
mutex
);
taosArrayPush
(
pCommon
->
pList
,
&
assignment
);
...
...
@@ -2422,7 +2422,7 @@ int32_t tmq_get_topic_assignment(tmq_t* tmq, const char* pTopicName, tmq_topic_a
pAssignment
->
begin
=
pClientVg
->
offsetInfo
.
walVerBegin
;
pAssignment
->
end
=
pClientVg
->
offsetInfo
.
walVerEnd
;
pAssignment
->
vg
roupHandle
=
pClientVg
->
vgId
;
pAssignment
->
vg
Id
=
pClientVg
->
vgId
;
}
if
(
needFetch
)
{
...
...
@@ -2524,7 +2524,7 @@ int32_t tmq_get_topic_assignment(tmq_t* tmq, const char* pTopicName, tmq_topic_a
}
}
int32_t
tmq_offset_seek
(
tmq_t
*
tmq
,
const
char
*
pTopicName
,
int32_t
vg
roupHandle
,
int64_t
offset
)
{
int32_t
tmq_offset_seek
(
tmq_t
*
tmq
,
const
char
*
pTopicName
,
int32_t
vg
Id
,
int64_t
offset
)
{
if
(
tmq
==
NULL
)
{
tscError
(
"invalid tmq handle, null"
);
return
TSDB_CODE_INVALID_PARA
;
...
...
@@ -2544,14 +2544,14 @@ int32_t tmq_offset_seek(tmq_t* tmq, const char* pTopicName, int32_t vgroupHandle
int32_t
numOfVgs
=
taosArrayGetSize
(
pTopic
->
vgs
);
for
(
int32_t
i
=
0
;
i
<
numOfVgs
;
++
i
)
{
SMqClientVg
*
pClientVg
=
taosArrayGet
(
pTopic
->
vgs
,
i
);
if
(
pClientVg
->
vgId
==
vg
roupHandle
)
{
if
(
pClientVg
->
vgId
==
vg
Id
)
{
pVg
=
pClientVg
;
break
;
}
}
if
(
pVg
==
NULL
)
{
tscError
(
"consumer:0x%"
PRIx64
" invalid vgroup id:%d"
,
tmq
->
consumerId
,
vg
roupHandle
);
tscError
(
"consumer:0x%"
PRIx64
" invalid vgroup id:%d"
,
tmq
->
consumerId
,
vg
Id
);
return
TSDB_CODE_INVALID_PARA
;
}
...
...
source/client/test/clientTests.cpp
浏览文件 @
4063cfbc
...
...
@@ -1144,7 +1144,7 @@ TEST(clientCase, sub_tb_test) {
taos_free_result
(
pRes
);
}
tmq_offset_seek
(
tmq
,
"topic_t1"
,
pAssign
[
0
].
vg
roupHandle
,
pAssign
[
0
].
begin
);
tmq_offset_seek
(
tmq
,
"topic_t1"
,
pAssign
[
0
].
vg
Id
,
pAssign
[
0
].
begin
);
}
tmq_consumer_close
(
tmq
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录