Decorator interface to pykafka
Project description
This module is based on pykafka project (https://github.com/Parsely/pykafka.git) and define a class KafkaDecorator and its 4 decorators
@KafkaDecorator.host The first defines the connection parameters its parameters are the same of pykafka.KafkaClient
@KafkaDecorator.balanced_consumer its parameters are the same of pykafka.topic.get_balanced_consumer function
@KafkaDecorator.simple_consumer its parameters are the same of pykafka.topic.get_simple_consumer function
its parameters are the same of pykafka.topic.get_producer function @KafkaDecorator.producer
Install
pip install kafka-client-decorators
How to use
from kafka_client_decorators import KafkaDecorator
from kafka_client_decorators.kafka.logging_helper import setDebugLevel
import logging
kc = KafkaDecorator( )
#@kc.host(zookeeper_hosts='localhost:2181' )
@kc.host(hosts='localhost:9092' )
class A:
def __init__(self, testA, cls):
self.a = testA
self.cls = cls
pass
@kc.balanced_consumer('test1', consumer_group='testgroup3', auto_commit_enable=True, managed=True, consumer_timeout_ms=1000)
def get(self, msg):
print ( f'{self.a} Receive offset {msg.offset} key {msg.partition_key} message: { msg.value }' )
self.send( msg.value )
@kc.simple_consumer('test2', consumer_group='testgroup4', auto_commit_enable=True, consumer_timeout_ms=1000)
def get2(self, msg):
print ( f'{self.a} Receive offset {msg.offset}, message: { msg.value }' )
self.cls.stop(self)
@kc.producer('test2')
def send(self, msg):
pass
@kc.producer('test1')
def sendKey(self, msg, key ):
pass
class B:
def __init__(self):
pass
def stop(self, conn):
conn.stop()
a = A('Example', B())
a.start()
a.sendKey( 'Hello'.encode('utf-8'), partition_key='world'.encode('utf-8') )
a.wait()
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
Built Distribution
Close
Hashes for kafka_client_decorators-0.8.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ba0b8808e30c4cd22d0b7907cd5923aad7e5ca16db79f321e154635e5c5f238 |
|
MD5 | 989a842c80d9ca7d79a891ce4c8c8414 |
|
BLAKE2b-256 | 24e5f64a5c528513b55cbdd233a2276410f5129215f10b57b81cbf51c1d04f4b |
Close
Hashes for kafka_client_decorators-0.8.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f82caed73d8d9c1b886b80f037424fe2677c43718db4886b1e49f5a580d03e3a |
|
MD5 | 2117ca227001afba340b128f1c05a6b0 |
|
BLAKE2b-256 | df66ab795d86ef27e41f4fb0917e1c5c73914c54a20f3bd69a63699e8fe168aa |