Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A Series of Notebooks on how to start with Kafka and Python

License

NotificationsYou must be signed in to change notification settings

Aiven-Labs/python-notebooks-for-apache-kafka

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

This is a series of Jupyter Notebooks on how to start with Apache Kafka® and Python.You can try these notebooks in order to learn the basic concepts of Apache Kafka in an environment containing markdown text, media and executable code on the same page.

The notebooks are based on a managed Apache Kafka instance created onAiven's website, but can be also customised to any Apache Kafka instance running locally with SSL authentication. Aiven's offer 300$ of free credit that you can redeem by creating your account onAiven's website.

If you have any question or improvement suggestion regarding the notebooks, please open an issue. Any contributions are welcome!

Start JupyterLab on Docker

You can access the notebooks via Jupyterlab, this example will be based on docker

  1. clone the repository
  2. open a terminal
  3. go to the folder where the repository has been cloned
  4. run the following
docker run --rm -p 8888:8888 \  -e JUPYTER_ENABLE_LAB=yes  \  -v "$PWD":/home/jovyan/work \  jupyter/datascience-notebook

You'll see a folder namedwork on the top left, under it you'll find the list of notebooks.

Notebook Overview

This repository contains the following notebooks.

Notebook Details

The notebooks are divided per Apache Kafka functionality.

Create Managed Apache Kafka and PostgreSQL instances withAiven.io

Create services

00 - Aiven Setup.ipynb notebook downloadsAiven's command line interface and creates an Apache Kafka and a PostgreSQL instance.

Please change<INSERT_TOKEN_HERE> and<INSERT_EMAIL_HERE> with a valid email address and token created onAiven's website. The notebook creates the instances and also stores all the required connection credentials locally.

Produce and read Messages to Apache Kafka

Producer

01 - Producer.ipynb Creates a Python Apache Kafka Producer and produces the first messages. After the first message is produced, open the02 - Consumer.ipynb notebook and pace it alongside the Producer.

Place consumer alongside the producer

02 - Consumer.ipynb reads from the topic where01 - Producer wrote. But it does it from the point in time that it attaches to Apache Kafka, not going back to history.

Consumer

If you want to read messages created with01 - Producer you need to run02 - Consumer.ipynb's last code block before producing any messages on01 - Producer. This behaviour is Apache Kafka's default and can be changed by adding a line'auto.offset.reset'='earliest' to the consumer properties.

Understanding Apache Kafka Partitions

Partitions

Partitions is Apache Kafka are a way to divide messages belonging to the same topic in sub-logs.

  • 03 - 00 - Partition Producer.ipynb creates a topic with two partitions usingKafkaAdmin and sends a message to each partition.We can then open both03 - 01 - Consumer - Partition 0.ipynb and03 - 02 - Consumer - Partition 1.ipynb which will read messages fromPartition 0 andPartition 1 respectively.

New Consumer Group

Consumer groups

Messages in Apache Kafka are not deleted when read from a consumer. This makes them available for other consumers to be read.04 - New Consumer Group.ipynb creates a new consumer part of the a new Consumer Group and reads from the topic where01 - Producer wrote. We can check now, by sending a message from the01 - Producer notebook, that we can receive it both in02 - Consumer.ipynb and04 - New Consumer Group.

Kafka Connect

Kafka Connect

Apache Kafka Connect® is a prebuilt framework enabling an easy integration of Apache Kafka with existing data sources or sinks. Aiven providesKafka connect as managed service making the integration a matter of a single config file.05 - Kafka Connect.ipynb: Creates a new Kafka topic containing messages with both schema and payload, and then pushes them to a PostgreSQL database via Apache Kafka Connect.

Delete Aiven Services

Delete services

Once you're done, you can delete all the services create onAiven's website by executing the code inON - Aiven - Delete Services.ipynb

Keep Reading

We maintain some other resources that you may also find useful:

License

This project is licensed under theApache License, Version 2.0.

Apache Kafka is either a registered trademark or trademark of the Apache Software Foundation in the United States and/or other countries. Aiven has no affiliation with and is not endorsed by The Apache Software Foundation.

About

A Series of Notebooks on how to start with Kafka and Python

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp