pipeline_kafka插件安装和使用
官方文档说明
pipelineDB可通过插件安装的形式集成kafka, 根据本人测试, 插件会起多个线程解析kafka数据, 一旦某条数据解析出现异常, 解析解析线程就会挂起, 直到下个周期才会被重启拉起.
个人使用感觉: 该插件容错性有待提高, 对日志的规整性要求很高, 只适用于低流量且数据格式规整的业务场景中.
插件安装
librdkafka安装
librdkafka为pipeline_kafka的依赖, 可通过apt安装或编译安装
apt安装
apt install librdkafka-dev
编译安装
git clone https://github.com/edenhill/librdkafka.git ~/librdkafka
cd librdkafka
./configure
# Or, to automatically install dependencies using the system's package manager:
# ./configure --install-deps
# Or, build dependencies from source:
# ./configure --install-deps --source-deps-only
make
sudo make install
pipeline_kafka安装
编译安装
git clone https://github.com/pipelinedb/pipeline_kafka.git ~/pipeline_kafka
cd pipeline_kafka
make
make install
修改postgres配置并重启
vim /etc/postgresql/11/main/postgresql.conf
# 修改配置
......
shared_preload_libraries = 'pipelinedb,pipeline_kafka'
# 重启postgres
service postgresql restart
# 创建插件
sudo -u postgres -i psql -c "CREATE EXTENSION pipeline_kafka;"
插件使用
添加broker
select pipeline_kafka.add_broker('broker1:9092,broker2:9092[,broker:port]');
消费topic中的数据到foreign table
-- 假定kafka中的数据为json格式, 消费topic中的数据到foreign table, 设置并行度为4
select pipeline_kafka.consume_begin('kafka_topic_name', 'topic_stream', format := 'json', parallelism := 4);
启动/停止
select pipeline_kafka.consume_begin();
select pipeline_kafka.consume_end();