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"
├── notes
│ ├── admin.py
│ ├── apps.py
│ ├── __init__.py
│ ├── kafka_producer.py
│ ├── migrations
│ │ ├── 0001_initial.py
│ │ ├── __init__.py
│ ├── models.py
│ ├── tests.py
import json
import sys
from kafka import KafkaProducer
from outboxexample import settings
import signal
producer = KafkaProducer(bootstrap_servers=[settings.KAFKA_HOST])
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path("admin/", admin.site.urls),
path("", include("notes.urls")),
]
from django.urls import path
from . import views
urlpatterns = [
path("notes", views.note_view, name="note_view"),
]
import json
from django.db import transaction
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
from .kafka_producer import publish_note_created
from .models import Note
consumer:
build: .
command: python kafka_consumer.py
volumes:
- .:/app
env_file:
- .env
depends_on:
kafka:
condition: service_healthy