Kafka-Vahfka
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-2.0.0.tar.gz
(2.3 kB
view details)
File details
Details for the file vahfka-2.0.0.tar.gz.
File metadata
- Download URL: vahfka-2.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
982ba0453180df191795151001c65dd9bc5582b3c13916328221d0a676c450c0
|
|
| MD5 |
fd36013604c004b44a540b48fe237b28
|
|
| BLAKE2b-256 |
41b2f87dd3d1066f9bb3720d0faf62e7674872cf0361dcae83097e44fba80843
|