目录
1. 前言
librdkafka提供的异步的生产接口,异步的消费接口和同步的消息接口,没有同步的生产接口。
2. 缩略语
缩略语
缩略语全称
示例或说明
rd
Rapid Development
rd.h
rk
RdKafka
toppar
Topic Partition
struct rd_kafka_toppar_t
{
};
rep
Reply,
struct rd_kafka_t {
rd_kafka_q_t *rk_rep
};
msgq
Message Queue
struct rd_kafka_msgq_t {
};
rkb
RdKafka Broker
Kafka代理
rko
RdKafka Operation
Kafka操作
rkm
RdKafka Message
Kafka消息
payload
存在Kafka上的消息(或叫Log)
3. 配置和主题
3.1. 配置和主题结构
3.1.1. Conf
配置接口,配置分两种:全局的和主题的。
3.1.2. ConfImpl
配置的实现。
3.1.3. Topic
主题接口。
3.1.4. TopicImpl
主题的实现。
4. 线程
RdKafka编程涉及到三类线程:
1) 应用线程,业务代码的实现
2) Kafka Broker线程rd_kafka_broker_thread_main,负责与Broker通讯,多个
3) Kafka Handler线程rd_kafka_thread_main,每创建一个consumer或producer即会创建一个Handler线程。
5. 消费者
5.1. 消费者结构
5.1.1. Handle
定义了poll等接口,它的实现者为HandleImpl。
5.1.2. HandleImpl
实现了消费者和生产者均使用的poll等,其中poll的作用为:
1) 为生产者回调消息发送结果;
2) 为生产者和消费者回调事件。
classHandle{
/**
* @brief Polls the provided kafka handle for events.
*
* Events will trigger application provided callbacks to be called.
*
* The \p timeout_ms argument specifies the maximum amount of time
* (in milliseconds) that the call will block waiting for events.
* For non-blocking calls, provide 0 as \p timeout_ms.
* To wait indefinately for events, p