Skip to main content

A small example package

Project description

Yet another kafka consumer which is born for the purpose of keeping Shop's discovery and experience systems updated with the data events/updates in the merchant system.

Installation

To use the consumer you can add it as a dependency to your project.

PIP

python -m pip install --user cb-kafka-consumer

Pipfile

[packages]
cb-kafka-consumer = "~=0.0.4"

An example handler

Make sure to use the right values to initiate CBKafkaConsumer

from cb_kafka_consumer.src.consumer import CBKafkaConsumer, Message


class MyConsumer:
    def __init__(self):
        self.__consumer = CBKafkaConsumer('my-topic', 'my-group-id', '127.0.0.1:9092', self.handler, batch_size=20)
        self.__consumer.start()

    def handler(self, msg: Message):
        print(msg.get_offset(), msg.msg, msg)
        self.__consumer.commit(msg)

Commit policy

There are two different approaches dealing with commit policy.

  • auto_commit=True

You can use auto_commit=True when initiating the consumer to instruct it to automatically commit received messages right after they have been handed over to the handler callback. When using auto_commit, the handler callback is not expected to explicitly call the commit method of consumer object.

  • auto_commit=False (default behavior)

If auto_commit is not specified or set to False the consumer will only commit messages right before the item in the sequence where it's not committed (handling may have probably failed). To further demonstrate this let's assume we the consumer has received messages with the following offsets:

1, 2, 3, 4, 5

The consumer now hands over the received messages to the handler callback. Now let's say the callback processes message #1 and #2 successfully and commits these two messages but fails to process #3. Next, messages #4 and #5 are successfully processed and committed. The consumer will only commit message #1 and #2 and will not commit succeeded messages until commit is called with message #3 and will only then move onward.

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

cb_kafka_consumer-0.0.5.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

cb_kafka_consumer-0.0.5-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file cb_kafka_consumer-0.0.5.tar.gz.

File metadata

  • Download URL: cb_kafka_consumer-0.0.5.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for cb_kafka_consumer-0.0.5.tar.gz
Algorithm Hash digest
SHA256 030f819ec951cae6eee32eb404878991dc6ba62ed86c02253ba671d217941627
MD5 39b13826df79346280eb52f5ca59605a
BLAKE2b-256 ff30cf644e2b182f348857ea45d20e63a5720fa5152c7a5c6a00c3953b327f55

See more details on using hashes here.

File details

Details for the file cb_kafka_consumer-0.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for cb_kafka_consumer-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 c8e155d2216b53053f4fd1d0776b00a12e7409a5f4d8d455a6a4d5bbcbc91c32
MD5 cfe3019d80140c7423c7866bb7d5020a
BLAKE2b-256 58a32ca1620bfb13b3459308fa1d1efbfafcd532ecae6a9091dc216d3015e248

See more details on using hashes here.

Supported by

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