This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
INSTALLED_APPS = [ | |
"django.contrib.admin", | |
"django.contrib.auth", | |
"django.contrib.contenttypes", | |
"django.contrib.sessions", | |
"django.contrib.messages", | |
"django.contrib.staticfiles", | |
"notes", | |
"jaiminho", | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pip install django-jaiminho |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
api_1 | Message published to Kafka: {'name': 'note-created', 'note': {'id': 2, 'title': 'My Note Title', 'content': 'This is the content of my note', 'created_at': '2023-05-02 12:57:25', 'updated_at': '2023-05-02 12:57:25'}} | |
consumer_1 | {'name': 'note-created', 'note': {'id': 2, 'title': 'My Note Title', 'content': 'This is the content of my note', 'created_at': '2023-05-02 12:57:25', 'updated_at': '2023-05-02 12:57:25'}} | |
api_1 | [02/May/2023 12:57:25] "POST /notes HTTP/1.1" 200 80 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http POST http://localhost:8000/notes title="My Note Title" content="This is the content of my note" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
consumer: | |
build: . | |
command: python kafka_consumer.py | |
volumes: | |
- .:/app | |
env_file: | |
- .env | |
depends_on: | |
kafka: | |
condition: service_healthy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
KAFKA_HOST=kafka:9092 | |
PYTHONUNBUFFERED=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
KAFKA_HOST = os.environ.get("KAFKA_HOST") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
python manage.py makemigrations | |
python manage.py migrate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
from django.db import models | |
from django.utils import timezone | |
class Note(models.Model): | |
id = models.AutoField(primary_key=True) | |
title = models.CharField(max_length=255) | |
content = models.TextField() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
from django.db import connection | |
connection.force_debug_cursor = True | |
l = logging.getLogger('django.db.backends') | |
l.setLevel(logging.DEBUG) | |
l.addHandler(logging.StreamHandler()) | |
my_model = MyModel.objects.get() |