Skip to main content

Veli Logger

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

velilogger-1.0.0.tar.gz (2.0 kB view details)

Uploaded Source

Built Distribution

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

velilogger-1.0.0-py3-none-any.whl (2.1 kB view details)

Uploaded Python 3

File details

Details for the file velilogger-1.0.0.tar.gz.

File metadata

  • Download URL: velilogger-1.0.0.tar.gz
  • Upload date:
  • Size: 2.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.6

File hashes

Hashes for velilogger-1.0.0.tar.gz
Algorithm Hash digest
SHA256 8e4373d6349d983cfc31440b01b5fbb4a4ea2a52aebab6c90ee291a72fb58be4
MD5 283c3cec37dc8cd823a736d8428c1c7f
BLAKE2b-256 90ea5d10e537a9e32fc0ac820776953972664cfc66ef309be8aa514acf87f409

See more details on using hashes here.

File details

Details for the file velilogger-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: velilogger-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 2.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.6

File hashes

Hashes for velilogger-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 db485ae3cf8fad7f0f26669f26cc36f3e6a3fc0097bdce38402d188ea183ba8e
MD5 fc86b5d7e60368ff7c7f4ec4c49d1d03
BLAKE2b-256 514e59f4e51e86b0b871b274d73debe13eff953d9adeb79ee9eacc5633d49b17

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