Skip to content

m-appel/kafka-wrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kafka-wrapper: A generic Kafka reader and writer

The purpose of this repository is to provide two simple wrapper classes for reading from and writing to Kafka topics, based on the confluent_kafka Python package. In addition, msgpack is used for data compression.

Installation

Make sure the required Python dependencies are installed:

pip install -r requirements.txt

Usage

Import the desired class, create an object and use within a with statement. Usage as a context manager is required, since the initialization of the producer/consumer happens in the __enter__ function.

Reader

from kafka_reader import KafkaReader

reader = KafkaReader(topic_list, bootstrap_servers)
with reader:
    for msg in reader.read():
        # Process message.

Writer

from kafka_writer import KafkaWriter

writer = KafkaWriter(topic, bootstrap_servers)
with writer:
    writer.write(key, data, timestamp)

For advanced usage, check the source code.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages