Skip to main content

A Kafka mock library that is designed to be used in integration tests for applications using librdkafka.

Project description

Kafka Simulator

Kafka Simulator is a mocking library for the confluent_kafka library used for Apache Kafka. This library allows integration tests to utilize Producer and Consumer instances without an actual connection to a Kafka Cluster.

Project Overview

The main component of this project is a process called KafkaSimulator which simulates the behavior of an actual Kafka Cluster, within the bounds of implementation limitations. The current version includes a KProducer class that acts as a mock for the Producer from the confluent_kafka package. A Consumer class is still under development.

Table of Contents

Installation

First, clone the repository:

git clone https://github.com/your-repo/kafka-simulator.git
cd kafka-simulator

You can install the necessary dependencies using:

pip install -r requirements.txt

Usage

Starting Kafka Simulator

Kafka Simulator is automatically run whenever any instance of KProdcer (e.g. via mock_producer) is created. So there is no need to manually start it.

Upon default logging settings a custom start-up messages might be visible:

INFO     kafka_simulator > Kafka Simulator initialized
INFO     ticking_thread  > Buffer for KProducer(4368687344): ticking initialized
INFO     buffer_handler  > Buffer for KProducer(4368687344) has been primed, size: 300, timeout: 2
INFO     kafka_simulator > Kafka Simulator initialized
INFO     kafka_simulator > Handle producers has been primed
INFO     kafka_simulator > Kafka Simulator initialized
INFO     ticking_thread  > Buffer for KProducer(4368687344): ticking started

KProducer

To use the KProducer class in your tests, you need to import it from the kafka_simulator package:

from confluent_kafka import Producer
from kafka_simulator import mock_producer

# Example usage
@mock_producer
def producer_factory(conf):
    return Producer(conf)


producer = producer_factory({'bootstrap.servers': 'localhost:9092'})
producer.produce(topic='test-topic', value='Test message')
producer.flush()

The KProducer class replicates the interface and behavior of the Producer class from the confluent_kafka library.

Contributing

We welcome contributions! Please see our contributing guidelines for more details.

License

This project is licensed under the MIT License. See the LICENSE file for details.

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

kafka_mocha-0.1.0a4.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

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

kafka_mocha-0.1.0a4-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file kafka_mocha-0.1.0a4.tar.gz.

File metadata

  • Download URL: kafka_mocha-0.1.0a4.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for kafka_mocha-0.1.0a4.tar.gz
Algorithm Hash digest
SHA256 fcb265f5a123873921fe9594652c41aebc70adc526a720167293855e86139064
MD5 a123c5458daab022c656e8eefea4df19
BLAKE2b-256 5eb65ab2c0d041260972987d81abc1a56e3c21e0688e1490b15ebbfd86c0a3fb

See more details on using hashes here.

Provenance

The following attestation bundles were made for kafka_mocha-0.1.0a4.tar.gz:

Publisher: pypi-publish.yml on Effiware/kafka-mocha

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kafka_mocha-0.1.0a4-py3-none-any.whl.

File metadata

  • Download URL: kafka_mocha-0.1.0a4-py3-none-any.whl
  • Upload date:
  • Size: 13.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for kafka_mocha-0.1.0a4-py3-none-any.whl
Algorithm Hash digest
SHA256 4810376870c6773949affdfa0c76fe160665c851f9cb8b216cbae59072e1e698
MD5 bd34a1db553792cd07668906ca341295
BLAKE2b-256 571c6a1410d532cea2d6967e58e2c9ee9f3a081172279d4254e9d452a8d7d0f1

See more details on using hashes here.

Provenance

The following attestation bundles were made for kafka_mocha-0.1.0a4-py3-none-any.whl:

Publisher: pypi-publish.yml on Effiware/kafka-mocha

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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