This is a Python code that processes image URLs from a Kafka topic, downloads the images, resizes them, and stores the result in a Redis database.
- Docker
- Kafka
- Redis
- Python
This guide will help you install Docker on your Windows machine.
Before you begin, make sure your system meets the following requirements:
- Windows 10 Pro, Enterprise, or Education edition.
- Virtualization must be enabled in BIOS/UEFI settings.
- At least 4GB of RAM.
-
Download Docker Desktop for Windows from the official website: Docker Desktop for Windows.
-
Run the installer and follow the on-screen instructions.
-
During installation, you may be prompted to enable Hyper-V and Windows Subsystem for Linux (WSL). Allow these features if prompted.
-
Once the installation is complete, launch Docker Desktop.
-
Docker should now be up and running on your Windows machine.
-
Open a command prompt or PowerShell and verify Docker is installed by running:
docker --version
Docker Desktop includes Docker Compose along with Docker Engine and Docker CLI which are Compose prerequisites.
-
Find
docker-compose-combined.yml
file in the sub-folder named ‘deploy’. -
Save the
docker-compose-combined.yml
file in your project directory. -
Open a terminal or command prompt and navigate to the directory where your
docker-compose-combined.yml
file is located. -
Run the following command to start the Redis, Kafka and ZooKeeper containers:
docker-compose -f docker-compose-combined.yml up -d
-
To verify that the containers are running, you can run the following command:
docker ps
Both Redis and Kafka are now up and running in Docker.
-
Start the Kafka server by typing this in the Kafka terminal
docker exec -it kafka /bin/sh
-
Redis CLI can also be used [Optional]
docker exec -it redis redis-cli
Configure redis on http://localhost:8001
Before running the script, ensure the installation and functioning of the following components:
-
Python 3
-
requests
library for making HTTP requests. -
shutil
library for file operations. -
kafka-python
library for Kafka integration. -
PIL
(Pillow) library for image processing. -
Redis server and Kafka server are running.
You can install the required Python libraries using pip:
pip install requests kafka-python Pillow redis
-
Start a Kafka producer to send messages with image URLs and output size information to the Kafka topic.
cd /opt/kafka_2.13-2.8.1/bin
Produce a message to your topic using the Kafka console producer:
kafka-console-producer.sh --broker-list kafka:9092 --topic <topic_name>
-
Run the 'agent.py' script in kafka-redis-agent folder using Python:
python agent.py --kafka-topic <topic_name>
-
The script will consume messages from the Kafka topic, download the images, resize them according to the specified dimensions, and store the results in Redis with keys like 'image0', 'image1', and so on.