Veli Kafka Client
Project description
Kafka Client for VELI.STORE
Description
This module helps you to integration kafka messaging into your apps. Supported frameworks: FastAPI, (Django coming soon :D)
How to use (FastAPI):
- Producer
app = FastAPI()
def produce_event(topic, event):
producer = app.state.producer
producer.produce_event(topic, event)
@app.on_event("startup")
async def startup_event():
bootstrap_servers = ['localhost:9092', 'localhost:9093']
producer = KafkaEventProducer(bootstrap_servers)
await producer.start()
app.state.producer = producer
@app.on_event("shutdown")
async def shutdown_event():
await app.state.producer.stop()
@app.post("/products")
async def save_product(product_info: ProductInfo):
product = save_product(product_info)
produce_event(KafkaTopic.PAGE_VIEWS, product)
return product
- Consumer
app = FastAPI()
@app.on_event("startup")
async def startup_event():
# Define the configuration variables
topics = [KafkaTopic.USER_REGISTRATIONS, KafkaTopic.PAGE_VIEWS]
bootstrap_servers = ['localhost:9092', 'localhost:9093']
group_id = 'app_id'
consumer = AsyncKafkaConsumer(topics, bootstrap_servers, group_id)
app.state.consumer = consumer
await consumer.start()
# start the consume_events coroutine in the background
asyncio.create_task(consumer.consume())
@app.on_event("shutdown")
async def shutdown_event():
await app.state.consumer.stop()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
kafkaclientveli-1.0.1.tar.gz
(4.5 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kafkaclientveli-1.0.1.tar.gz.
File metadata
- Download URL: kafkaclientveli-1.0.1.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b08f2633c60b389100859b89721f9486a71fc79dddafb788ad1e0e5fa821e10c
|
|
| MD5 |
0d9ec47b6b4d1c04b4bf410c9d8bd898
|
|
| BLAKE2b-256 |
2cd93a040996ff9d435fdc5b453f3a4153acb19abcc1b93a88f0c8fd49240668
|
File details
Details for the file kafkaclientveli-1.0.1-py3-none-any.whl.
File metadata
- Download URL: kafkaclientveli-1.0.1-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da8c0b4ccd7866227b7383dd7c2ffd4596811e90a7a29c6e0349c4d78b31d388
|
|
| MD5 |
039858be345b65a88674205b5007b7eb
|
|
| BLAKE2b-256 |
0f328f2f792eb8785c3300f8ab3738cc2dc7bc510d90a73014e3718e5319bbb2
|