Skip to content

Latest commit

 

History

History
102 lines (67 loc) · 2.33 KB

producer-consumer.md

File metadata and controls

102 lines (67 loc) · 2.33 KB

Testing the Kafka Cluster by pushing a sample video frame

Pre-requisite

  • Apache Kafka Cluster Setup - Follow this
  • Create an instance outside Kafka Cluster with Docker binaries installed

Setting up Environment for Producer Script

Pulling the Container

docker pull ajeetraina/opencv4-python3

Running the container exposing port 5000

docker run -itd -p 5000:5000 ajeetraina/opencv4-python3 bash
docker attach <container-id>

Cloning the Repository

git clone https://github.com/collabnix/pico
cd pico/kafka/

If in case it reports that pico already exists, remove it first and then try the above command. I still need to package it properly.

Modify the producer

Two entries needed to be changed:

  • topic name(which you must have supplied during the initial Kafka cluster configuration)
  • bootstrapper server IP pointing to your Kafka Broker
import sys
import time
import cv2
# from picamera.array import PiRGBArray
# from picamera import PiCamera
from kafka import KafkaProducer
from kafka.errors import KafkaError

topic = "testpico"

def publish_video(video_file):
    """
    Publish given video file to a specified Kafka topic. 
    Kafka Server is expected to be running on the localhost. Not partitioned.
    
    :param video_file: path to video file <string>
    """
    # Start up producer
    producer = KafkaProducer(bootstrap_servers='10.140.0.2:9092')
def publish_camera():
  """
  Publish camera video stream to specified Kafka topic.
  Kafka Server is expected to be running on the localhost. Not partitioned.
  """

  # Start up producer
  producer = KafkaProducer(bootstrap_servers='10.140.0.2:9092')

Downloading a sample video

Download a sample video and rename it as Countdown1.mp4. Place it here in the same directory where producer and consumer resides.

Executing the Script

python producer.py

Setting up Environment for Consumer Script

Open up consumer script and modify the two important items:

  • Topic Name: testpico
  • Bootstrap Server: :9093

Executing the Script

python consumer.py

Verifying the Video Streaming

By now you can browse through http://:5000 to see video streaming.