Consumer#
-
class Consumer#
- Header-file:
#include <datasystem/stream/consumer.h>
- Namespace:
datasystem
流缓存消费者。
公共函数
-
Consumer()#
构造流缓存消费者实例。注:consumer对象并非线程安全,所以当有多个线程尝试调用同一个consumer做操作时会返回K_SC_STREAM_IN_USE错误码。
- 返回:
流缓存消费者实例。
-
~Consumer()#
析构流缓存消费者实例,析构过程中会自动断开与 Worker 的连接,释放消费者持有的资源。
-
Status Receive(uint32_t expectNum, uint32_t timeoutMs, std::vector<Element> &outElements)#
消费者接收数据带有订阅功能,接收数据会等待接收expectNum个elements的时候返回成功,或者当超时时间timeoutMs到达返回成功。
- 参数:
expectNum - 期望接收elements的个数。
timeoutMs - 超时时间, 单位ms, 在超时时间内未收到期望个数的element时, 接口返回K_OK
outElements - 实际接收到的elements,详见
Element章节。
- 返回:
返回值状态码为
StatusCode::K_OK时表示接收成功,否则返回其他错误码。
-
Status Receive(uint32_t timeoutMs, std::vector<Element> &outElements)#
消费者获取到element后立刻返回。如果没有element,将等待直到超时时间到达。
- 参数:
timeoutMs - 超时时间, 单位ms, 在超时时间内未收到期望个数的element时, 接口返回K_OK
outElements - 实际接收到的elements,详见
Element章节。
- 返回:
返回值状态码为
StatusCode::K_OK时表示接收成功,否则返回其他错误码。
-
Status Ack(uint64_t elementId)#
消费者接收完某elementId标识的element后,需要确认已消费完,使得各个worker上可以获取到是否所有消费者都已经消费完的信息,若所有消费者都消费完某个Page, 可以触发内部的内存回收机制。若不Ack,则在消费者退出时候才会自动Ack。
- 参数:
elementId - 待确认已消费完成的element的id 。
- 返回值
返回值状态码为
StatusCode::K_OK时表示确认成功,否则返回其他错误码。