Skip to main content

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


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

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kafkaclientveli-1.0.10-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file kafkaclientveli-1.0.10.tar.gz.

File metadata

  • Download URL: kafkaclientveli-1.0.10.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

Hashes for kafkaclientveli-1.0.10.tar.gz
Algorithm Hash digest
SHA256 ea5717dfe9c1484a4ecdbeeb04201e981b34dd9b913f9d5383877350ee66d8bb
MD5 2ff726da3d6110711be641c0cb9d9295
BLAKE2b-256 9acfd7e5b4cb5b4e8760b7c9fe1c901d2f0f5ef7fbe90bb3d2d79da55ddf1e49

See more details on using hashes here.

File details

Details for the file kafkaclientveli-1.0.10-py3-none-any.whl.

File metadata

File hashes

Hashes for kafkaclientveli-1.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 e152c6687a96cb9815242217173d5293bfb9d4053c86ddaa01c8843c89eb42f8
MD5 38ccf8824e625cb40af20efccf056d41
BLAKE2b-256 ab06a449bb85c55b0ff026ff79b007d9e22ffe52ae4846d9c1f1d231650fe2d7

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