Skip to content

denisecase/buzzline-02-case

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

buzzline-02-case

Streaming data is often too big for any one machine. Apache Kafka is a popular streaming platform that uses publish-subscribe patterns:

  • Producers publish streaming data to topics
  • Consumers subscribe to topics to process data in real-time

We'll write Python producers and consumers to work with Kafka topics.

Kafka needs space - it's big.

It also comes from the Linux world. We'll use WSL on Windows machines.

Copy This Example Project & Rename

  1. Copy/fork this project into your GitHub account and create your own version of this project to run and experiment with.
  2. Name it buzzline-02-yourname where yourname is something unique to you.

Task 1. Install and Start Kafka (using WSL if Windows)

Before starting, ensure you have completed the setup tasks in https://github.com/denisecase/buzzline-01-case first. Python 3.11 is required.

In this task, we will download, install, configure, and start a local Kafka service.

  1. Install Windows Subsystem for Linux (Windows machines only)
  2. Install Kafka Streaming Platform
  3. Start the Kafka service (leave the terminal open).

For detailed instructions, see:

Task 2. Manage Local Project Virtual Environment

Open your project in VS Code and use the commands for your operating system to:

  1. Create a Python virtual environment
  2. Activate the virtual environment
  3. Upgrade pip
  4. Install from requirements.txt

Windows

Open PowerShell terminal in VS Code (Terminal / New Terminal / PowerShell).

py -3.11 -m venv .venv
.venv\Scripts\Activate.ps1
py -m pip install --upgrade pip wheel setuptools
py -m pip install --upgrade -r requirements.txt

If you get execution policy error, run this first: Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

Mac / Linux

python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade -r requirements.txt

Task 3. Start a Kafka Producer

Producers generate streaming data for our topics.

In VS Code, open a terminal. Use the commands below to activate .venv, and start the producer.

Windows PowerShell:

.venv\Scripts\activate
py -m producers.kafka_producer_case

Mac/Linux:

source .venv/bin/activate
python3 -m producers.kafka_producer_case

Task 4. Start a Kafka Consumer

Consumers process data from topics or logs in real time.

In VS Code, open a NEW terminal in your root project folder. Use the commands below to activate .venv, and start the consumer.

Windows PowerShell:

.venv\Scripts\activate
py -m consumers.kafka_consumer_case

Mac/Linux:

source .venv/bin/activate
python3 -m consumers.kafka_consumer_case

Later Work Sessions

When resuming work on this project:

  1. Open the project folder in VS Code.
  2. Start the Kafka service (in WSL if Windows).
  3. Activate your local project virtual environment (.venv) in your OS-specific terminal.

Save Space

To save disk space, you can delete the .venv folder when not actively working on this project. You can always recreate it, activate it, and reinstall the necessary packages later. Managing Python virtual environments is a valuable skill.

License

This project is licensed under the MIT License as an example project. You are encouraged to fork, copy, explore, and modify the code as you like. See the LICENSE file for more.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages