Skip to main content

No project description provided

Project description

Guido

Guido is a library that simplifies the integration with Apache Kafka and streamlines the creation of Kafka consumers. It offers easy setup, automatic offset management, and built-in error handling, helping you quickly build reliable and efficient Kafka consumer applications.

Features

  • Easy Kafka Integration: Seamlessly connect to Kafka clusters.
  • Simplified Consumer Setup: Quickly create and manage Kafka consumers.
  • Automatic Offset Management: Handle offsets automatically.
  • Error Handling: Built-in error handling and retry mechanisms.

Getting Started

To use Kafka Consumer Helper, follow these steps:

Install the library: Add guido to your project. For example, if you're using pip, you can install it with:

pip install guido-kafka

Configure Kafka Service: Set up your Kafka service connection with the required parameters.

Create and Start the Consumer: Use the Guido class and KafkaService to create a consumer and start processing messages.

Example Usage

Here’s a simple example of how to use guido in your project:

from guido import Guido, KafkaConfig

# Create a new Guido application
app = Guido(
    config=KafkaConfig(bootstrap_servers="localhost:29092", group_id="foo")
)

# Define a function to process messages from the 'my_topic' topic
@app.subscribe('my_topic')
def process_message(message: dict):
    print(message)

Save the file as test_app.py and run

guido test_app.app

Producing messages

You can produce messages easily through a command

guido test_app.app produce my_topic '{"foo": "bar"}'

Message to be produced must be a valid JSON

Checking pending messages

Also you can check how many messages there are in a topic partition pending to process

guido test_app.app pending-messages my_topic

Configuring Guido with Environment Variables

Guido can be configured using environment variables, which can be useful for managing configuration settings in different environments (e.g., development, staging, production) without hardcoding values in your source code.

Just create your app without using any configuration

app = Guido()

Then set GUIDO_HOSTS and GUIDO_GROUP_ID. Take into account that any configuration passed to Guido constructor takes priority over environment variables

Error handling

Guido has built-in error handling mechanisms to ensure that messages are processed reliably. If an exception is raised while processing a message, Guido captures the error and takes the necessary steps to manage it.

  1. Sends the message to a Dead Letter Topic (DLT): The problematic message is sent to a designated Dead Letter Topic (DLT). This helps in isolating messages that failed processing and allows for further investigation and troubleshooting. Guido creates by default a DLT named <original_topic>_<group_id>_dlt.
  2. Committing the Original Message: After sending the message to the DLT, Guido commits the original message's offset. This means that the consumer will not attempt to reprocess the same message, avoiding potential processing loops and ensuring that the consumer continues processing new messages.

If you want, you can tell guido what DLT to use for a message

@app.subscribe('my_topic', dead_letter_topic='custom_topic')
def process_message(message: dict):
    print(message)

License

This project is licensed under the MIT License. See the LICENSE file for more details.

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

guido_kafka-0.2.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

guido_kafka-0.2-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file guido_kafka-0.2.tar.gz.

File metadata

  • Download URL: guido_kafka-0.2.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.6

File hashes

Hashes for guido_kafka-0.2.tar.gz
Algorithm Hash digest
SHA256 e3d8da8ab768dd3094967c10c89d58379578001e75bd304a6580bda5ed39dbdd
MD5 42897a7e98e1e716d53fee3a27a180ce
BLAKE2b-256 9565ce47d68762eb4e545fd5ecc5cc11dcf060e4725824691e9b399ca9add2cd

See more details on using hashes here.

File details

Details for the file guido_kafka-0.2-py3-none-any.whl.

File metadata

  • Download URL: guido_kafka-0.2-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.6

File hashes

Hashes for guido_kafka-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 65d081499a6c8265afea65d9272e68a33bd58cd2c3d5e882e46250a57eb69dce
MD5 59ac07d032d4c221735fabed6ad88f90
BLAKE2b-256 983dbbb26a1c0a2a50933d23ab230ed5bc0597e7eff6194af8e6eb27ddfe36f3

See more details on using hashes here.

Supported by

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