Skip to main content

Kafka

Project description

vahfka

The vahfka library simplifies Kafka interaction by providing convenient abstractions for both producing and consuming messages. It seamlessly integrates with the kafka-python library and offers additional features for asynchronous message sending and context management.

Installation

You can install the vahfka library using pip:

pip install vahfka

Usage

Initializing the Kafka Producer:

from vahfka import KafkaProducerWithCallbacks

Create a KafkaProducerWithCallbacks instance

kafka_producer = KafkaProducerWithCallbacks(bootstrap_servers='localhost:9092')

Sending Messages:

Synchronous Message Sending:

# Send a message synchronously
kafka_producer.send_message(topic='example_topic', message={'key': 'value'})

Asynchronous Message Sending:

# Send a message asynchronously
kafka_producer.send_message_async(topic='example_topic', message={'key': 'value'})
Kafka Consumer Wrapper:
from vahfka import KafkaConsumerWrapper

# Create a KafkaConsumerWrapper instance
kafka_consumer = KafkaConsumerWrapper(
    bootstrap_servers='localhost:9092',
    group_id='my-group',
    topics=['example_topic']
)
Consuming Messages:
# Consume messages from Kafka topic
messages = kafka_consumer.consume_messages()
print(messages)
Context Management:
# Use the KafkaProducerWithCallbacks as a context manager
with KafkaProducerWithCallbacks(bootstrap_servers='localhost:9092') as producer:
    producer.send_message(topic='example_topic', message={'key': 'value'})

Example

from vahfka import KafkaProducerWithCallbacks, KafkaConsumerWrapper

# Initialize KafkaProducerWithCallbacks and KafkaConsumerWrapper instances
kafka_producer = KafkaProducerWithCallbacks(bootstrap_servers='localhost:9092')
kafka_consumer = KafkaConsumerWrapper(
    bootstrap_servers='localhost:9092',
    group_id='my-group',
    topics=['example_topic']
)

# Send a message
kafka_producer.send_message(topic='example_topic', message={'key': 'value'})

# Consume messages
messages = kafka_consumer.consume_messages()
print(messages)

For questions, issues, or contributions, please visit the https://gitlab.com/magmam/egov

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

vahfka-1.0.0.tar.gz (2.3 kB view details)

Uploaded Source

File details

Details for the file vahfka-1.0.0.tar.gz.

File metadata

  • Download URL: vahfka-1.0.0.tar.gz
  • Upload date:
  • Size: 2.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.5

File hashes

Hashes for vahfka-1.0.0.tar.gz
Algorithm Hash digest
SHA256 451e44f67f5e0e25ce8cc0d705029f001545f7b94bdc1bb1d803c17d0440a14d
MD5 f3f602788c906cceeaec6adcfc7554ce
BLAKE2b-256 11c194cd5dcce08cbded664e262ae050af1614293fe398cbfe7b09b32eeb3f83

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