一 kafka 环境搭建
kafka官网的安装说明:https://kafka.apache.org/quickstart,具体步骤如下:
1. 安装jdk
$ apt-get update && apt-get install openjdk-8-jdk -y
2. 安装kafka
https://www.apache.org/dyn/closer.cgi?path=/kafka/3.3.1/kafka_2.13-3.3.1.tgz
$ tar -xzf kafka_2.13-3.3.1.tgz
$ cd kafka_2.13-3.3.1
3 开启两个服务器
# Start the ZooKeeper service
$ ./bin/zookeeper-server-start.sh config/zookeeper.properties
# start a new teminal, Start the Kafka broker service
$ ./bin/kafka-server-start.sh config/server.properties
4. 测试kafka
4.1 创建主题,这条命令只用执行一次,执行完会自己退出。
$ ./bin/kafka-topics.sh --create --topic deepstream --bootstrap-server localhost:9092
4.2 开启消费者
$ ./bin/kafka-console-consumer.sh --topic deepstream --from-beginning --bootstrap-server localhost:9092
#按ctrl+c退出
deepstream工具测试
deepstream的安装和介绍,详见其官网是Quickstart Guide — DeepStream 6.1.1 Release documentation
到/opt/nvidia/deepstream/deepstream/sources/libs/kafka_protocol_adaptor下,修改test_kafka_proto_sync.cpp, 如下将topic1改成deepsream。
- //Subscribe to topics
-
- const char *topics[] = {"deepstream", "topic2"};
-
- if (msgapi_send_ptr(conn_handle, (char *)"deepstream", (const uint8_t*) SEND_MSG, \
然后安装编译器apt-get install protobuf-compiler, 执行编译,make -f Makefile.test, 然后执行./test_kafka_proto_sync,发现开启消费者的窗口能收到数据。
默认连的是这个地址#define KAFKA_CONNECT_STR "localhost;9092"。
打印如下:
./test_kafka_proto_sync
Refer to nvds log file for log output
Adapter protocol=KAFKA , version=2.0
connection signature queried=
send [0] completed
send [1] completed
send [2] completed
send [3] completed
send [4] completed
Disconnecting in 3 secs
Python deepstream-test4测试
python3 deepstream_test_4.py -i /opt/nvidia/deepstream/deepstream/samples/streams/sample_720p.h264 -p /opt/nvidia/deepstream/deepstream/lib/libnvds_kafka_proto.so --conn-str="localhost;9092" -t deepstream -s 0 --no-display
C++ deepstream-test4测试
以deepstream-test4为例,更改配置文件,填入正确的conn-str和topic。
- msgbroker:
- proto-lib: /opt/nvidia/deepstream/deepstream/lib/libnvds_kafka_proto.so
- conn-str: localhost;9092
- topic: deepstream
这里不要写成:con-str:
日志:
PAYLOAD_DEEPSTREAM级别
./bin/kafka-console-consumer.sh --topic deepstream --from-beginning --bootstrap-server localhost:9092
{
"messageid" : "26ed04be-1f78-44b3-9a9b-73e69a2c4baf",
"mdsversion" : "1.0",
"@timestamp" : "2022-11-17T15:00:21.139Z",
"place" : {
"id" : "1",
"name" : "XYZ",
"type" : "garage",
"location" : {
"lat" : 30.32,
"lon" : -40.549999999999997,
"alt" : 100.0
},
"aisle" : {
"id" : "walsh",
"name" : "lane1",