Pulsar IO 模块依赖 Pulsar function,部署及架构参考Apache Pulsar 官方链接:
编译Pulsar-io-iotdb Sink插件
下载pulsar源码。
git clone https://github.com/apache/pulsar.git
将iotdb.tar sink源码解压至pulsar/pulsar-io目录下,在pulsar/pulsar-io/pom.xml文件添加iotdb项,如图所示:
在pulsar目录下 编译iotdb sink。
mvn clean package -pl pulsar-io/iotdb -am -Dmaven.test.skip=true
编译成功后,在pulsar/pulsar-io/iotdb目录下生成target目录,target目录下会有pulsar-io-iotdb-3.0.0.nar插件包。
创建IoTDB容器
# 创建 docker bridge 网络
docker network create --driver=bridge --subnet=172.18.0.0/16 --gateway=172.18.0.1 iotdb
dockerfile
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
version: "3"
services:
iodb-confignode:
image: apache/iotdb:1.1.0-confignode
hostname: iotdb-confignode
container_name: iotdb-confignode
environment:
- cn_internal_address=iotdb-confignode
- cn_internal_port=10710
- cn_consensus_port=10720
- cn_target_config_node_list=iotdb-confignode:10710
volumes:
- ./data/confignode:/iotdb/data
- ./logs/confignode:/iotdb/logs
networks:
iotdb:
ipv4_address: 172.18.0.3
iotdb-datanode1:
image: apache/iotdb:1.1.0-datanode
hostname: iotdb-datanode-1
container_name: iotdb-datanode-1
ports:
- "6667:6667"
environment:
- dn_rpc_address=iotdb-datanode-1
- dn_internal_address=iotdb-datanode-1
- dn_target_config_node_list=iotdb-confignode:10710
- dn_rpc_port=6667
- dn_mpp_data_exchange_port=10740
- dn_schema_region_consensus_port=10750
- dn_data_region_consensus_port=10760
volumes:
- ./data/datanode1:/iotdb/data/
- ./logs/datanode1:/iotdb/logs/
networks:
iotdb:
ipv4_address: 172.18.0.6
iotdb-datanode2:
image: apache/iotdb:1.1.0-datanode
hostname: iotdb-datanode-2
container_name: iotdb-datanode-2
environment:
- dn_rpc_address=iotdb-datanode-2
- dn_internal_address=iotdb-datanode-2
- dn_target_config_node_list=iotdb-confignode:10710
- dn_rpc_port=6667
- dn_mpp_data_exchange_port=10740
- dn_schema_region_consensus_port=10750
- dn_data_region_consensus_port=10760
volumes:
- ./data/datanode2:/iotdb/data/
- ./logs/datanode2:/iotdb/logs/
networks:
iotdb:
ipv4_address: 172.18.0.4
networks:
iotdb:
external: true
运行
docker-compose up –d
,成功会有拉起三个容器:
运行
docker exec -ti iotdb-datanode-1 /iotdb/sbin/start-cli.sh -h iotdb-datanode-1
进入iotdb容器并连接iotdb数据库
创建Pulsar proxy容器
运行
docker run -d --name proxy -p 6650:6650 -p 8080:8080 --network=iotdb apachepulsar/pulsar-all:latest bin/pulsar standalone
IoTDB sink 测试
- cd pulsar目录,使用
包拷贝至pulsar proxy容器内。docker cp pulsar-io/iotdb/target/pulsar-io-iotdb-3.0.0.nar proxy:/pulsar/connectors 将生成的pulsar-io-iotdb-3.0.0.nar
- 运行
进入pulsar proxy 容器内部docker exec -it proxy /bin/sh
- 创建主题:
bin/pulsar-admin topics create persistent://public/default/my-topic
- 运行sink:
bin/pulsar-admin sinks localrun \
--archive connectors/pulsar-io-iotdb-3.0.0.nar \
--tenant public \
--namespace default \
--name iotdb-sink \
--sink-config '{"host": "172.18.0.6","port": 6667,"user": "root","password": "root","batchSize": 1,"storageGroup": "root.iotdb1.device1"}' \
--inputs my-topic
- 另起一个客户端运行
进入pulsar proxy容器内部docker exec -it proxy /bin/sh
- 分别发送两次消息:
bin/pulsar-client produce my-topic -s "\n" -m {"temperature":18,"timestamp":1686021685001}
bin/pulsar-client produce my-topic -s "\n" -m {"temperature":23,"timestamp":1686021685005}
- 另起客户端,运行
进入iotdb容器并连接iotdb数据库docker exec -ti iotdb-datanode-1 /iotdb/sbin/start-cli.sh -h iotdb-datanode-1
- 运行
select * from root.iotdb1.device1
可查阅iotdb数据已存在,测试OK.
Pulsar sink 常见命令
Create
创建 sink
Go |
常用参数
- -a,--archive : 指定 sink 的 NAR 包
- --classname : 指定 sink 的类名称
- -i,--inputs : 指定 sink 的 topic,多个 topic 用逗号隔开
- --name : 指定 sink 的名称
- --namespace : 指定 sink 的命名空间
- --parallelism : 指定 sink 的并发数
- --sink-config-file : 指定 sink 的 yaml 配置文件
- --tenant : 指定 sink 的租户
Update
更新 sink
Go |
常用参数
- -a,--archive : 指定 sink 的 NAR 包
- --classname : 指定 sink 的类名称
- -i,--inputs : 指定 sink 的 topic,多个 topic 用逗号隔开
- --name : 指定 sink 的名称
- --namespace : 指定 sink 的命名空间
- --parallelism : 指定 sink 的并发数
- --sink-config-file : 指定 sink 的 yaml 配置文件
- --tenant : 指定 sink 的租户
Delete
删除 sink
Go |
常用参数
- --name : 指定 sink 的名称
- --namespace : 指定 sink 的命名空间
- --tenant : 指定 sink 的租户
List
显示所有 sink
Go |
常用参数
- --namespace : 指定 sink 的命名空间
- --tenant : 指定 sink 的租户
Get
显示 sink 的信息
Go |
常用参数
- --name : 指定 sink 的名称
- --namespace : 指定 sink 的命名空间
- --tenant : 指定 sink 的租户
Status
显示 sink 的状态
Go |
常用参数
- --instance-id : 指定 sink 的实例 ID
- 如果未指定,则获取所有实例的状态
- --name : 指定 sink 的名称
- --namespace : 指定 sink 的命名空间
- --tenant : 指定 sink 的租户
Stop
停止 sink
Go |
常用参数
- --instance-id : 指定 sink 的实例 ID
- 如果未指定,则停止所有实例的状态
- --name : 指定 sink 的名称
- --namespace : 指定 sink 的命名空间
- --tenant : 指定 sink 的租户
Start
启动 sink
Go |
常用参数
- --instance-id : 指定 sink 的实例 ID
- 如果未指定,则启动所有实例
- --name : 指定 sink 的名称
- --namespace : 指定 sink 的命名空间
- --tenant : 指定 sink 的租户
Restart
重启 sink
Go |
常用参数
- --instance-id : 指定 sink 的实例 ID
- 如果未指定,则获取所有实例的状态
- --name : 指定 sink 的名称
- --namespace : 指定 sink 的命名空间
- --tenant : 指定 sink 的租户
Localrun
本地运行
在本地运行一个 Pulsar IO sink connector,方便调试。
Go |
常用参数
- -a,--archive : 指定 source 的 NAR 包
- --classname : 指定 sink 的类名称
- -i,--inputs : 指定 sink 的 topic,多个 topic 用逗号隔开
- --name : 指定 sink 的名称
- --namespace : 指定 sink 的命名空间
- --parallelism : 指定 sink 的并发数
- --sink-config-file : 指定 sink 的 yaml 配置文件
- --tenant : 指定 sink 的租户