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
velikafkaclient-1.0.0.tar.gz
(5.1 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 velikafkaclient-1.0.0.tar.gz.
File metadata
- Download URL: velikafkaclient-1.0.0.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
92633f1168ccf7c82906c81368189aac9329b5884a69f152a4002b0dcb996f7b
|
|
| MD5 |
335ccfd3a1f45f2a5bea4f3d0b5de004
|
|
| BLAKE2b-256 |
c48ebcb8c4ee6b925e716e6b14ef5540c6e813371c08203bd30a3c0dfa3c0877
|
File details
Details for the file velikafkaclient-1.0.0-py3-none-any.whl.
File metadata
- Download URL: velikafkaclient-1.0.0-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 |
f37ea9221f3c10ce98b79125f6917be761c36f334b332d310bcc1463904c8898
|
|
| MD5 |
d2be32636755c414c536fc848a02e346
|
|
| BLAKE2b-256 |
c7edb9e5d73c6def32684f4bd8b624e81bd35849b43142a2f5e9ac34e828d579
|