Skip to main content

Kafka Channels backend

Project description

Contributors Forks Stargazers Issues MIT


Channels 🔗 Kafka

channels-kafka

A Django Channels channel layer that uses Kafka as its backing store.
Explore the docs »

Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Contributing
  5. Testing
  6. License
  7. Contact

About The Project

Provides channel layer for django channels using kafka

(back to top)

Built With

  • Django
  • Kafka

(back to top)

Getting Started

To work with django channels using this channel layer you will need to have working kafka cluster. As of time of writing, this library was only tested on Kafka with Kraft Mode.

Prerequisites

channels-kafka should be able to be installed using any package manager of your choice, although ci tests use uv

Installation

  • uv
    uv add channels-kafka
    
  • pip
    pip install channels-kafka
    

(back to top)

Usage

Assuming that you already have a working django-channels app using any other layer, the only thing you would need to do in your django code is to change CHANNEL_LAYERS setting in your django to use this backend with all releavant configuration.

CHANNEL_LAYERS = {
    "default": {
        "BACKEND": "channels_kafka.core.KafkaChannelLayer",
        "CONFIG": {
            "hosts": os.getenv("KAFKA_HOSTS", "localhost:9092").split(","),
            "client_id": os.getenv("KAFKA_CLIENT_ID", socket.gethostname()),
            "topic": os.getenv("KAFKA_CLIENT_ID", "channels-kafka"),
            "group_id": os.getenv("KAFKA_GROUP_ID", "channels-kafka-group"),
        },
    },
}

As for kafka broker, you would need to:

  • create desired topic
  • set offsets.topic.replication.factor to 1 since channels documentation says you should be ok with some messages not being delivered to increase throughput
  • set max.in.flight.requests.per.connection to 1 to ensure that messages are delivered in order

Both settings can be scoped only to created topic aswell

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

Testing

Check all caps constants in https://github.com/PawelKawula/channels-kafka/blob/master/tests/test_core.py to see which env variables you need to provide to run tests using your kafka cluster and then run

  pytest

(back to top)

Top contributors:

contrib.rocks image

License

Distributed under the MIT license. See LICENSE for more information.

(back to top)

Contact

Project Link: https://github.com/PawelKawula/channels-kafka

(back to top)

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

channels_kafka-0.1.1.tar.gz (26.4 kB view details)

Uploaded Source

Built Distribution

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

channels_kafka-0.1.1-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file channels_kafka-0.1.1.tar.gz.

File metadata

  • Download URL: channels_kafka-0.1.1.tar.gz
  • Upload date:
  • Size: 26.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.8

File hashes

Hashes for channels_kafka-0.1.1.tar.gz
Algorithm Hash digest
SHA256 1109d6789d5ab48135e7c23c17d24f18c2df6b6676a2015002ec71a52b46931f
MD5 408dff4096c5cf280ff0ec56d63d0d74
BLAKE2b-256 f954135e0917ddf3fc4bb942b5b123fa211b24d9bc21fb896f19d83fd586d002

See more details on using hashes here.

File details

Details for the file channels_kafka-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for channels_kafka-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 625688c6c9f8cd7f5c78124a3b86015f0190816d9c4c18163e073165ee17dcd8
MD5 949999ad1c4b9d79d8b30fdbe7050260
BLAKE2b-256 3ce63391721c21da8d66607ea83e92395c7913cd4cb899cec920796e1f28cd8a

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