Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Python Django as Producer and Consumer using Apache Kafka for content queue and Celery for task queue

License

NotificationsYou must be signed in to change notification settings

addu390/django-kafka

Repository files navigation

Django + Kafka + Celery 🚀

Confluent Installation (Local set-up)

  • pip install confluent-kafka
  • Download confluent platform from:https://www.confluent.io/download/ and unzip the file.
  • export CONFLUENT_HOME=<path-to-confluent>
  • export PATH=$PATH:$CONFLUENT_HOME/bin
  • $CONFLUENT_HOME/bin/confluent-hub install \ --no-prompt confluentinc/kafka-connect-datagen:latest

The output would be:

Running in a "--no-prompt" mode...Completed
  • Start the service:confluent local startThe output should resemble:
Starting ZookeeperZookeeper is [UP]Starting KafkaKafka is [UP]Starting Schema RegistrySchema Registry is [UP]Starting Kafka RESTKafka REST is [UP]Starting ConnectConnect is [UP]Starting KSQL ServerKSQL Server is [UP]Starting Control CenterControl Center is [UP]
  • Stop services:confluent local stop

Or set-up Kafka and Zookeeper Separately

Kafka

  • Simply put, Kafka is a distributed publish-subscribe messaging system that maintains feeds of messages in partitioned and replicated topics.
  • In the simplest way there are three players in the Kafka ecosystem: producers, topics (run by brokers) and consumers.

Installation Zookeeper (MacOS)

  • brew install zookeeper
  • Where is installation directory of zookeeper :/usr/local/Cellar/zookeeper

Start Zookeeper

  • In foregroundzkServer start
  • In backgroundbrew services start zookeeper

Installation Kafka (MacOS)

  • brew install kafka
  • Where is installation directory of Kafka :/usr/local/Cellar/kafka

Start Kafka

  • In foregroundbrew services start kafka
  • In backgroundzookeeper-server-start /usr/local/etc/kafka/zookeeper.properties & kafka-server-start /usr/local/etc/kafka/server.properties

For details on how to set-up a django project with best practices:https://pyblog.xyz/django-initial-setup/

Celery Installation - For polling

  • pip install amqp

  • pip install celery==4.4.0 (Note: Celery 5.0 is not compatible with django-celery-beat)

  • pip install django-celery-beat

  • Start worker and beatcelery -A django_kafka beat -l INFO -S django

  • Start RabbitMQbrew services start rabbitmq

Update settings.py

INSTALLED_APPS = [    ...,    'django_celery_beat',]
  • Run migrations:python manage.py migrate django_celery_beat

Note: In this project, the same Django project is the Producer and Consumer, but you can choose you have a standalone consumer.

Have a look at:

Note: The project is an example for Django application as a producer/consumer 😋

About

Python Django as Producer and Consumer using Apache Kafka for content queue and Celery for task queue

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp