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

It is not clear how many times each consumer poll operation needs to be performed #24857

Open
ntucz opened this issue Feb 23, 2024 · 5 comments
Assignees
Labels
help wanted Extra attention is needed question Further information is requested

Comments

@ntucz
Copy link

ntucz commented Feb 23, 2024

subscription_problem
注释部分代码是原来直接判断如果poll返回数据是空,直接跳出循环。
发现总是得不到订阅数据。
改成200次poll,结果发现times在114的时候,获取到结果。当然,大部分时候是第一次就能获取到结果。
这个太难理解,如果200次完了都没有poll到呢。
有没有更好的方法呢。

@ntucz ntucz added help wanted Extra attention is needed question Further information is requested labels Feb 23, 2024
@yu285 yu285 changed the title 数据订阅#不清楚每次consumer的poll操作需要执行多少次 It is not clear how many times each consumer poll operation needs to be performed Feb 25, 2024
@ntucz
Copy link
Author

ntucz commented Mar 8, 2024

官方这个问题么有答复?

@yu285
Copy link
Contributor

yu285 commented Mar 8, 2024

收到 我们看下

@yu285 yu285 self-assigned this Mar 8, 2024
@sheyanjie-qq
Copy link
Contributor

消息订阅的应用场景一般是要一直订阅的,当订阅的 topic 对应的表如果有新插入数据,都会poll到消息。

你如果想订阅到一条消息就退出循环,可以这么改:
while (time > 0) 改成 while (true)

在if (!obj.isEmpty()){
....
//增加一行
break;
}

@ntucz
Copy link
Author

ntucz commented Mar 11, 2024

消息订阅的应用场景一般是要一直订阅的,当订阅的 topic 对应的表如果有新插入数据,都会poll到消息。

你如果想订阅到一条消息就退出循环,可以这么改: while (time > 0) 改成 while (true)

在if (!obj.isEmpty()){ .... //增加一行 break; }

谢谢,consumer.poll(Duration.ofMillis(100)),这里的poll周期是毫秒级,而且非阻塞,即使没数据线程也继续跑,poll的结果是null,外面必须套个while(true)。
通常iot设备上报数据的周期很长,一直consumer.poll,太浪费cpu,所以我整了个定时器,周期到的时候再new 一个consumer去poll,但是不能确定第几次能得到数据。
https://www.taosdata.com/tdengine-engineering/1277.html
1710142556798
c++的这段代码,红框中是得不到就break,但是对照我最上面的问题,有可能第一次就是得不到,而是第5次才得到,这样第一次break就有问题了。

@sheyanjie-qq
Copy link
Contributor

你开始的例子是用的java连接器,因此我给你的答复也是基于java连接器
判断条件是if (!obj.isEmpty()) 就是拿到数据了,此时可以break的
播客的时间比较早了,你可以参考官网代码样例,比较新

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants