Base Kafka Consumer for Busie Projects
Project description
Busie Consumer
A base consumer package for Busie projects. Abstracts polling and configuration setup away from the end user and exposes basic api for starting the poll process.
Installation
pip install busie-consumer
Usage
from busie_consumer import BaseConsumer
CONFIG = {
'bootstrap.servers': 'localhost:9092',
# Other Config as necessary
}
consumer = BaseConsumer(topics=['some-topic', 'another'], config=CONFIG)
for message in consumer.start():
handle_message(message)
# It may also be helpful to extend this base class and provide helper methods
class HigherLevelConsumer(Consumer):
def handle_message(self, message):
# process the message
reply_topic, reply = determine_reply(message)
self.send_reply(topic=reply_topic, message=reply, key=message.key())
consumer = HigherLevelConsumer(topics=['topic'], config=CONFIG)
for msg in consumer.start():
consumer.handle_message(msg)
API
BaseConsumer
Public Methods
BaseConsumer(topics=None, config=None)
: Constructor- required param
topics
: An iterable of strings containing topic names - required param
config
: Adict
containing Kafka config Noteconfig
must havebootstrap.servers
andgroup.id
entries
- required param
start()
: Generator methods. initiates polling. returns a generatorclose()
: Closes the consumersend_reply(topic=None, message=None, key=None)
: Invokes a producer and uses it to send a reply to the desired topic. Especially helpful for theSaga Orchestrator
Pattern Note The producer assumes the same config as the consumer class- required param
topic
: A string representing the desired topic name - required param
message
: The data to send to the desired topic. - required param
key
: The desired key for the message
- required param
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
busie-consumer-1.0.0.tar.gz
(3.6 kB
view hashes)
Built Distribution
Close
Hashes for busie_consumer-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e5e2bda1e7563cc6badbc5e1a23acf5010a209cc3fc49fc8dd94012f1040512 |
|
MD5 | 92b3f54b1d3601b2a2bcdb3d72679033 |
|
BLAKE2b-256 | 608f03c8c0952721a1f831e96910f56e5272ffd3d1ec8d9166c40baf70bb2cb6 |