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.1.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

guido_kafka-0.2.1-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: guido_kafka-0.2.1.tar.gz
  • Upload date:
  • Size: 9.4 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.1.tar.gz
Algorithm Hash digest
SHA256 0aeb17cbe4a9acc2fc49f1022a10ce3152f48fd027e3ad5d3dd1392c47efc4dc
MD5 e54ab174ee9793d3c317d655912fef22
BLAKE2b-256 54809ffb10c371b7e8d6c81250591956ba4bee8554aa5c208fb9261b7666ecae

See more details on using hashes here.

File details

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

File metadata

  • Download URL: guido_kafka-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 9.2 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d79508b4573a9ba9ccede17c7bc061848e314b0b72ea455ffa590e6759ee0ca5
MD5 d1183cc8d8791275b32f911c8d61b076
BLAKE2b-256 9ebc8328e90f63810c76eb9a5ed3a88c2077a4fd2cd18090828d384ab956f4c6

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