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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fcb265f5a123873921fe9594652c41aebc70adc526a720167293855e86139064
|
|
| MD5 |
a123c5458daab022c656e8eefea4df19
|
|
| BLAKE2b-256 |
5eb65ab2c0d041260972987d81abc1a56e3c21e0688e1490b15ebbfd86c0a3fb
|
Provenance
The following attestation bundles were made for kafka_mocha-0.1.0a4.tar.gz:
Publisher:
pypi-publish.yml on Effiware/kafka-mocha
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kafka_mocha-0.1.0a4.tar.gz -
Subject digest:
fcb265f5a123873921fe9594652c41aebc70adc526a720167293855e86139064 - Sigstore transparency entry: 156334683
- Sigstore integration time:
-
Permalink:
Effiware/kafka-mocha@9bb0b310be8b43b0812cfd0dd55c7c8c8e934045 -
Branch / Tag:
refs/tags/0.1.0a4 - Owner: https://github.com/Effiware
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@9bb0b310be8b43b0812cfd0dd55c7c8c8e934045 -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4810376870c6773949affdfa0c76fe160665c851f9cb8b216cbae59072e1e698
|
|
| MD5 |
bd34a1db553792cd07668906ca341295
|
|
| BLAKE2b-256 |
571c6a1410d532cea2d6967e58e2c9ee9f3a081172279d4254e9d452a8d7d0f1
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kafka_mocha-0.1.0a4-py3-none-any.whl -
Subject digest:
4810376870c6773949affdfa0c76fe160665c851f9cb8b216cbae59072e1e698 - Sigstore transparency entry: 156334685
- Sigstore integration time:
-
Permalink:
Effiware/kafka-mocha@9bb0b310be8b43b0812cfd0dd55c7c8c8e934045 -
Branch / Tag:
refs/tags/0.1.0a4 - Owner: https://github.com/Effiware
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@9bb0b310be8b43b0812cfd0dd55c7c8c8e934045 -
Trigger Event:
release
-
Statement type: