Skip to main content
SDK Version: Next
DX-STREAM manual (PDF)

MsgBroker Pipeline

The pipeline demonstrates how to process a local video file with the YOLOv5s model for object detection, convert the results into a structured message format (e.g., JSON), and publish them to a message broker such as MQTT or Kafka for downstream applications.

Basic MsgBroker Pipeline Process​

This section demonstrates how to run a basic message broker pipeline demo using MQTT or Kafka

The pipeline in the figure is defined in dx_stream/pipelines/broker/*.sh and can be used as a reference for execution.

Explanation​

Element Descriptions

  • dxmsgconv: Transform element that processes inference metadata from upstream DxPostprocess elements and converts it into structured message payloads (typically JSON) using a user-defined custom library. The element requires a library-file-path property pointing to the custom message conversion library.
  • dxmsgbroker: Sink element that transmits payload messages to external message brokers (MQTT or Kafka) using a Broker Abstraction Layer (BAL) that provides unified interface for different broker types.

Usage Notes​

Pipeline Execution

  • Server Side: Run the DX-STREAM pipeline with broker output on the processing server
  • Client Side: Run the consumer application to receive and process messages

Basic Properties

  • dxmsgconv: Converts inference metadata to JSON format
  • dxmsgbroker: Publishes messages to MQTT/Kafka broker

Quick Start Demo​

This section demonstrates how to run a basic message broker pipeline demo using MQTT or Kafka.

MQTT Demo​

1. Server Setup (Processing Server with Message Broker)

# Install and start Mosquitto MQTT broker
sudo apt install mosquitto mosquitto-clients
sudo systemctl start mosquitto
sudo systemctl enable mosquitto
NOTE

By default, Mosquitto only accepts connections from localhost. To allow remote consumers, add the following to /etc/mosquitto/mosquitto.conf:

listener 1883 0.0.0.0
allow_anonymous true

Then restart the service: sudo systemctl restart mosquitto

2. Run DX-STREAM Pipeline (Server Side)

# Execute the broker pipeline on processing server
# The pipeline uses YOLOv5s model for object detection and converts to JSON messages
cd /path/to/dx_stream/dx_stream
./pipelines/broker/run_dxmsgbroker_mqtt.sh

# Or run manually with custom settings
gst-launch-1.0 \
urisourcebin uri=file:///path/to/your/video.mp4 ! decodebin ! \
dxpreprocess config-file-path=configs/YoloV5S_PPU/preprocess_config.json ! \
dxinfer config-file-path=configs/YoloV5S_PPU/inference_config.json ! \
dxpostprocess config-file-path=configs/YoloV5S_PPU/postprocess_config.json ! \
dxmsgconv library-file-path=/usr/local/share/gstdxstream/lib/libdx_msgconvl.so config-file-path=configs/msgconv_config.json ! \
dxmsgbroker broker-name=mqtt conn-info=localhost:1883 topic=test

3. Client Application (Any Machine - Consumer Only)

# Install Python MQTT client library (client machine only needs this)
pip install paho-mqtt

# Run the MQTT client to receive messages from server
python3 /usr/local/share/gstdxstream/bin/mqtt_sub_example.py -n <server_ip> -p 1883 -t test

# Or for C++ version
mqtt_sub_example -n <server_ip> -t test -p 1883

Kafka Demo​

1. Server Setup (Processing Server with Message Broker)

This example uses Kafka 4.3.1 in KRaft mode for a single-node demo. Kafka 4.0+ no longer supports ZooKeeper and requires Java 17 or later to run the broker.

# Install Java 17 explicitly (default-jdk may install Java 11)
sudo apt update
sudo apt install openjdk-17-jdk
java -version

# Download and extract Kafka (skip if already installed)
wget https://downloads.apache.org/kafka/4.3.1/kafka_2.13-4.3.1.tgz
tar -xzf kafka_2.13-4.3.1.tgz
cd kafka_2.13-4.3.1

# Initialize KRaft storage (first time only)
KAFKA_CLUSTER_ID=$(bin/kafka-storage.sh random-uuid)
bin/kafka-storage.sh format -t "$KAFKA_CLUSTER_ID" -c config/server.properties --standalone

# Start the broker in the foreground; use another terminal for the pipeline
bin/kafka-server-start.sh config/server.properties
Java version

Confirm that java -version reports Java 17 or later before running Kafka. If it still reports Java 11, select Java 17 with sudo update-alternatives --config java. If JAVA_HOME is set, it must also point to a Java 17+ installation, because Kafka uses it instead of the default java.

Initialize storage only once

Run all Kafka commands from the extracted Kafka root directory, not its bin/ directory. If storage is already initialized, skip UUID generation and formatting; restart using only bin/kafka-server-start.sh config/server.properties. Do not delete existing data or reformat storage to resolve an initialization error. The default log.dirs is /tmp/kraft-combined-logs; for persistent use, change it to a durable directory before the first format.

After the broker starts, verify connectivity from another terminal in the Kafka root directory:

bin/kafka-topics.sh --bootstrap-server localhost:9092 --list

An empty list is normal if no topics have been created yet.

NOTE

If the consumer runs on a different machine from the broker, set advertised.listeners in config/server.properties to the broker's IP:

advertised.listeners=PLAINTEXT://<broker_ip>:9092

Then restart the Kafka server. Without this, remote consumers will fail to resolve the broker's internal hostname.

2. Run DX-STREAM Pipeline (Server Side)

# Execute the broker pipeline on processing server
cd /path/to/dx_stream/dx_stream
./pipelines/broker/run_dxmsgbroker_kafka.sh

# Or run manually with custom settings
gst-launch-1.0 \
urisourcebin uri=file:///path/to/your/video.mp4 ! decodebin ! \
dxpreprocess config-file-path=configs/YoloV5S_PPU/preprocess_config.json ! \
dxinfer config-file-path=configs/YoloV5S_PPU/inference_config.json ! \
dxpostprocess config-file-path=configs/YoloV5S_PPU/postprocess_config.json ! \
dxmsgconv library-file-path=/usr/local/share/gstdxstream/lib/libdx_msgconvl.so config-file-path=configs/msgconv_config.json ! \
dxmsgbroker broker-name=kafka conn-info=localhost:9092 topic=test

3. Client Application (Any Machine - Consumer Only)

# Install Python Kafka client library (client machine only needs this)
python3 -m pip install --upgrade pip
python3 -m pip install confluent-kafka

# Run the Kafka client to receive messages from server
python3 /usr/local/share/gstdxstream/bin/kafka_consume_example.py -n <server_ip> -p 9092 -t test

# Or for C++ version
kafka_consume_example -n <server_ip> -p 9092 -t test

Windows​

On Windows, pre-built batch scripts are provided at dx_stream/pipelines/windows/:

broker_mqtt.bat :: MQTT pipeline (localhost:1883)
broker_kafka.bat :: Kafka pipeline (localhost:9092)

Scripts auto-detect DXSTREAM_ROOT from their location — no environment variable setup needed.

Broker server required

install.bat installs only the client libraries (libmosquitto, librdkafka) needed to build DX-Stream. A separate broker server must be running before executing the pipeline.

MQTT (Mosquitto)

Download the Windows installer from mosquitto.org/download and install. Then start the broker:

mosquitto -v

Or start as a Windows service via Services panel (services.msc).

Kafka

Kafka 4.0+ uses KRaft mode (ZooKeeper is no longer supported) and requires Java 17 or later to run the broker.

  • (1) Download JDK 17 or later from adoptium.net (MSI installer recommended) and install. Confirm with java -version; if JAVA_HOME is set, it must point to the same supported JDK.

  • (2) Download Kafka binary from kafka.apache.org/downloads and extract to a short path (e.g., C:\kafka).

Use a short path for Kafka

Extracting Kafka under a long path (e.g., inside a user's git repo folder) causes ("The input line is too long") errors in the batch scripts.

Always extract to a short path like C:\kafka.

  • (3) Initialize storage once, then start the broker from C:\kafka. On subsequent starts, run only the broker start command:
cd C:\kafka

:: Generate a cluster UUID
bin\windows\kafka-storage.bat random-uuid
:: → copy the printed UUID, e.g. KxWspAMDQNmidYkTX2KZcw

:: Format storage (first time only)
bin\windows\kafka-storage.bat format -t <UUID> -c config\server.properties --standalone

:: Start broker
bin\windows\kafka-server-start.bat config\server.properties

Running the pipelines

:: from dx_stream repo root
.\dx_stream\pipelines\windows\broker_mqtt.bat
.\dx_stream\pipelines\windows\broker_kafka.bat

Custom video (optional):

.\dx_stream\pipelines\windows\broker_mqtt.bat "C:\path\to\video.mp4"

Consumer apps are bundled at install\share\gstdxstream\bin\:

  • mqtt_sub_example.exe / mqtt_sub_example.py
  • kafka_consume_example.exe / kafka_consume_example.py
Kafka: start consumer before pipeline

The C++ consumer (kafka_consume_example.exe) starts reading from the latest offset, so it does not receive messages published before it connected. The Python consumer reads from the beginning. Start the consumer first, then run the pipeline:

:: Terminal 1 — consumer first
install\share\gstdxstream\bin\kafka_consume_example.exe -n localhost -p 9092 -t test

:: Terminal 2 — then pipeline
.\dx_stream\pipelines\windows\broker_kafka.bat

Unknown topic or partition on first launch is normal — the topic is created automatically once the pipeline runs.

MQTT has no such constraint — consumer can connect before or after the pipeline.

MQTT consumer:

install\share\gstdxstream\bin\mqtt_sub_example.exe -n localhost -p 1883 -t test
:: or Python
python install\share\gstdxstream\bin\mqtt_sub_example.py -n localhost -p 1883 -t test

Kafka consumer:

install\share\gstdxstream\bin\kafka_consume_example.exe -n localhost -p 9092 -t test
:: or Python
python install\share\gstdxstream\bin\kafka_consume_example.py -n localhost -p 9092 -t test

Network Architecture​

Processing Server:

  • DX-STREAM Pipeline (dxmsgconv + dxmsgbroker)
  • Message Broker Service (MQTT/Kafka)

Client Machine:

  • Consumer Application (Python/C++)
  • Only needs client library (paho-mqtt/confluent-kafka)
  • No broker service needed

Connection:

  • Processing Server ←→ Client Machine via network

Requirements:

  • Server: DX-STREAM + Message Broker Service (MQTT/Kafka)

  • Client: Only consumer application + client library (paho-mqtt/confluent-kafka)

NOTE

Replace <server_ip> with the actual IP address of your processing server. For local testing, use localhost.

Pipeline Properties​

The broker pipelines use the following key properties:

DxMsgConv Element:

  • config-file-path: Path to the JSON configuration file for the element's properties (library-file-path, message-interval, include-frame) (optional)

  • library-file-path: Path to custom message converter library (required)

  • message-interval: Frame interval for message conversion (default: 1)

DxMsgBroker Element:

  • broker-name: Message broker type - "mqtt" or "kafka" (required)

  • conn-info: Connection string in format host:port (required)

  • topic: Topic name for message publishing (required)

  • config: Path to broker configuration file for advanced settings (optional)


Advanced MsgBroker Configuration​

This section describes the detailed steps required to set up secure communication for the MQTT and Kafka message brokers, including SSL/TLS encryption and client authentication

MQTT Security Configuration​

SSL/TLS Encryption Setup​

1. Generate CA Certificate and Server Keys

# Create Root CA
openssl genrsa -out ca.key 2048
openssl req -new -x509 -days 360 -key ca.key -out ca.crt -subj "/C=KR/ST=KK/L=SN/O=DXS/OU=Test/CN=TestCA"

# Create Server Certificate (CN must match hostname)
openssl genrsa -out server.key 2048
openssl req -new -out server.csr -key server.key -subj "/C=KR/ST=KK/L=SN/O=DXS/OU=Server/CN=DXS-BROKER"
openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt -days 360
openssl verify -CAfile ca.crt server.crt

# Create Client Certificate (for client authentication)
openssl genrsa -out client.key 2048
openssl req -new -out client.csr -key client.key -subj "/C=KR/ST=KK/L=SN/O=DXS/OU=Client/CN=DXS-CLIENT"
openssl x509 -req -in client.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out client.crt -days 360
openssl verify -CAfile ca.crt client.crt

# Move certificates to mosquitto directories
sudo mkdir -p /etc/mosquitto/ca_certificates /etc/mosquitto/certs
sudo mv ca.crt /etc/mosquitto/ca_certificates/
sudo mv ca.key /etc/mosquitto/ca_certificates/
sudo mv server.crt server.key /etc/mosquitto/certs/
sudo mv client.crt client.key /etc/mosquitto/certs/

# Set correct ownership and permissions
sudo chown mosquitto:mosquitto /etc/mosquitto/ca_certificates/ca.crt
sudo chown mosquitto:mosquitto /etc/mosquitto/certs/server.crt /etc/mosquitto/certs/server.key
sudo chmod 644 /etc/mosquitto/ca_certificates/ca.crt
sudo chmod 600 /etc/mosquitto/ca_certificates/ca.key
sudo chmod 644 /etc/mosquitto/certs/server.crt
sudo chmod 600 /etc/mosquitto/certs/server.key
sudo chmod 644 /etc/mosquitto/certs/client.crt
sudo chmod 600 /etc/mosquitto/certs/client.key

2. Configure Mosquitto Server

# Edit /etc/mosquitto/mosquitto.conf
sudo tee /etc/mosquitto/mosquitto.conf << 'EOF'
# Basic settings
persistence true
persistence_location /var/lib/mosquitto/
log_dest file /var/log/mosquitto/mosquitto.log
include_dir /etc/mosquitto/conf.d

# Global auth settings (apply to all listeners)
allow_anonymous false
password_file /etc/mosquitto/passwd

# Plain MQTT port
listener 1883

# TLS MQTT port
listener 8883
cafile /etc/mosquitto/ca_certificates/ca.crt
certfile /etc/mosquitto/certs/server.crt
keyfile /etc/mosquitto/certs/server.key
require_certificate false
use_identity_as_username false
EOF

3. Setup Authentication

# Create user credentials
sudo mosquitto_passwd -b /etc/mosquitto/passwd user 1234
sudo chmod 644 /etc/mosquitto/passwd
sudo chown root:mosquitto /etc/mosquitto/passwd

# Restart mosquitto
sudo systemctl restart mosquitto
sudo systemctl status mosquitto

4. Test Connection

# Test plain MQTT (port 1883)
mosquitto_sub -h localhost -p 1883 -t test -u user -P 1234

# Test TLS MQTT (port 8883) - in another terminal
# For self-signed certificates, use --insecure option
mosquitto_sub -h localhost -p 8883 -t test -u user -P 1234 --cafile /etc/mosquitto/ca_certificates/ca.crt --insecure

# Publish test message
mosquitto_pub -h localhost -p 8883 -t test -u user -P 1234 --cafile /etc/mosquitto/ca_certificates/ca.crt --insecure -m "TLS test message"

5. DxMsgBroker Configuration File

Create broker_mqtt.cfg:

# Authentication
username = user
password = 1234

# Client ID (optional)
client-id = dx_stream_client

# SSL/TLS Configuration
tls_enable = 1
tls_insecure = 1
tls_cafile = /etc/mosquitto/ca_certificates/ca.crt
tls_capath = /etc/mosquitto/ca_certificates
tls_certfile = /etc/mosquitto/certs/client.crt
tls_keyfile = /etc/mosquitto/certs/client.key

6. Modify DX-Stream Pipeline

gst-launch-1.0 -e urisourcebin uri=file://$INPUT_VIDEO_PATH ! decodebin ! \
dxpreprocess config-file-path=$SRC_DIR/configs/YoloV5S_PPU/preprocess_config.json ! queue ! \
dxinfer config-file-path=$SRC_DIR/configs/YoloV5S_PPU/inference_config.json ! queue ! \
dxpostprocess config-file-path=$SRC_DIR/configs/YoloV5S_PPU/postprocess_config.json ! queue ! \
dxmsgconv config-file-path=$SRC_DIR/configs/msgconv_config.json ! queue ! \
dxmsgbroker broker-name=mqtt conn-info=localhost:8883 topic=test config=$SRC_DIR/configs/broker_mqtt.cfg

Kafka Security Configuration​

SSL/TLS Setup for Kafka​

1. Generate Certificates for Kafka

Follow the librdkafka SSL guide for detailed certificate generation.

2. Configure Kafka Server (server.properties)

# SSL Configuration
ssl.protocol=TLS
ssl.enabled.protocols=TLSv1.2,TLSv1.3
ssl.keystore.type=JKS
ssl.keystore.location=/path/to/kafka.server.keystore.jks
ssl.keystore.password=server_keystore_password
ssl.key.password=server_key_password
ssl.truststore.type=JKS
ssl.truststore.location=/path/to/kafka.server.truststore.jks
ssl.truststore.password=server_truststore_password
ssl.client.auth=required

3. DxMsgBroker Kafka Configuration

Create broker_kafka.cfg:

[kafka]
# Message size limits
message.max.bytes=10485760

# SSL Configuration
security.protocol=ssl
ssl.ca.location=/path/to/ca-cert.pem
ssl.certificate.location=/path/to/client-cert.pem
ssl.key.location=/path/to/client-key.pem
ssl.key.password=client_key_password