Skip to main content

Confluent kafka Wrapper to publish messages to Kafka broker with a defined Structure

Project description

Repo Setup

Setup aws cli with DE-prod account credentials

export CODEARTIFACT_AUTH_TOKEN=`aws codeartifact get-authorization-token --domain simpl --domain-owner 950779425701 --region ap-south-1 --query authorizationToken --output text`                             
poetry config repositories.simpl_utils https://aws:$CODEARTIFACT_AUTH_TOKEN@simpl-950779425701.d.codeartifact.ap-south-1.amazonaws.com/pypi/pypi-store/
poetry config repositories.simpl_kafka_event_publisher https://aws:$CODEARTIFACT_AUTH_TOKEN@simpl-950779425701.d.codeartifact.ap-south-1.amazonaws.com/pypi/pypi-store/

Kafka Config

Below are the available options available for configuring kafka producer behavior

Attribute Kafka Config Mapping Default Value
bootstrap_servers bootstrap.servers Required
client_id client.id ""
linger_ms linger.ms 5ms
batch_size batch.size 16384
delivery_timeout_ms delivery.timeout.ms 120000
batch_num_messages batch.num.messages 1000
compression_type compression.type none
acks acks all
connections_max_idle_ms connections.max.idle.ms 540000
queue_buffering_max_messages queue.buffering.max.messages 100000
queue_buffering_max_kbytes queue.buffering.max.kbytes 100

Usage

  1. Define a KafkaConfig Object
config = KafkaConfig(
    bootstrap_servers="localhost:29092",
    linger_ms=1,
    batch_size=1,
    queue_buffering_max_messages=1,
    batch_num_messages=1
)
  1. Create a KafkaEventPublisher Object
producer = KafkaEventProducer(config)
  1. Create an event object schema by inheriting from BaseEventModel
class CustomEventModel(BaseEventModel):
    phone_number: str
    user_id: str

...
event = CustomEventModel(phone_number="1234567890", user_id="123")
  1. Publish messages to kafka using above producer, providing topic name and event
producer.publish("some_topic", event)

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

simpl_kafka_wrapper-0.2.3.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

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

simpl_kafka_wrapper-0.2.3-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file simpl_kafka_wrapper-0.2.3.tar.gz.

File metadata

  • Download URL: simpl_kafka_wrapper-0.2.3.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.9 Darwin/22.6.0

File hashes

Hashes for simpl_kafka_wrapper-0.2.3.tar.gz
Algorithm Hash digest
SHA256 bc432d85095410b3eba0194c71181c40991809660baafffe784fc04e4d91b022
MD5 6abb8fb54470056a01f35a8aaded4f3f
BLAKE2b-256 cdd855976b675203fef40cde8772a9fc50927c7f37e56c5152712b22522df9f8

See more details on using hashes here.

File details

Details for the file simpl_kafka_wrapper-0.2.3-py3-none-any.whl.

File metadata

File hashes

Hashes for simpl_kafka_wrapper-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 fbb33d3fe8f783b469ab960b905dfe83e2caa4383178d9e38e0bd26fe154a664
MD5 912a9e634fd5d10f0cc9c5a530e80693
BLAKE2b-256 b54b6ea212595ce86f4f57f25b1c179e6b9ab142b56824ee7471732a6578cb02

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