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.1.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.1-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

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

Hashes for kafkaclientveli-1.0.1.tar.gz
Algorithm Hash digest
SHA256 b08f2633c60b389100859b89721f9486a71fc79dddafb788ad1e0e5fa821e10c
MD5 0d9ec47b6b4d1c04b4bf410c9d8bd898
BLAKE2b-256 2cd93a040996ff9d435fdc5b453f3a4153acb19abcc1b93a88f0c8fd49240668

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kafkaclientveli-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 da8c0b4ccd7866227b7383dd7c2ffd4596811e90a7a29c6e0349c4d78b31d388
MD5 039858be345b65a88674205b5007b7eb
BLAKE2b-256 0f328f2f792eb8785c3300f8ab3738cc2dc7bc510d90a73014e3718e5319bbb2

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