Skip to main content

Decorator interface to pykafka

Project description

Decorators to kafka

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 and its parameters are the same of pykafka.KafkaClient

  • @KafkaDecorator.balanced_consumer defines a balanced consumer and its parameters are the same of pykafka.topic.get_balanced_consumer function

  • @KafkaDecorator.simple_consumer defines a simple consumer and its parameters are the same of pykafka.topic.get_simple_consumer function

  • @KafkaDecorator.producer defines a producer and its parameters are the same of pykafka.topic.get_producer function

Install

pip install kafka-client-decorators

Example

from kafka_client_decorators import KafkaDecorator

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kafka_client_decorators-0.9.11.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kafka_client_decorators-0.9.11-py3-none-any.whl (19.5 kB view details)

Uploaded Python 3

File details

Details for the file kafka_client_decorators-0.9.11.tar.gz.

File metadata

  • Download URL: kafka_client_decorators-0.9.11.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.5

File hashes

Hashes for kafka_client_decorators-0.9.11.tar.gz
Algorithm Hash digest
SHA256 6397199e1b9d251d2ec6fb60ac812c8b3fc5690073871076dbcdfd43c1cc5493
MD5 54ea29c68075442be1e146eadbc3dee5
BLAKE2b-256 18c209d9e6125b3c16d01706537e6a0bb8ab1316955c540e2dba24c6100e0eee

See more details on using hashes here.

File details

Details for the file kafka_client_decorators-0.9.11-py3-none-any.whl.

File metadata

  • Download URL: kafka_client_decorators-0.9.11-py3-none-any.whl
  • Upload date:
  • Size: 19.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.5

File hashes

Hashes for kafka_client_decorators-0.9.11-py3-none-any.whl
Algorithm Hash digest
SHA256 7f38dc84ac8accff79773a196e16ab7bca58f97634bb196c2411665024caca6a
MD5 bace30c29148a56e2735bc0392f14b57
BLAKE2b-256 f34b45df35130b8398b8e36ca61a5066598cc5568dede13e0bfbcb2988a5e806

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page