Skip to content

Instantly share code, notes, and snippets.

View antunesleo's full-sized avatar

Leonardo Antunes antunesleo

View GitHub Profile
INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"notes",
"jaiminho",
]
pip install django-jaiminho
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
http POST http://localhost:8000/notes title="My Note Title" content="This is the content of my note"
consumer:
build: .
command: python kafka_consumer.py
volumes:
- .:/app
env_file:
- .env
depends_on:
kafka:
condition: service_healthy
KAFKA_HOST=kafka:9092
PYTHONUNBUFFERED=1
import os
KAFKA_HOST = os.environ.get("KAFKA_HOST")
python manage.py makemigrations
python manage.py migrate
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()
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()