This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
| ├── notes | |
| │ ├── admin.py | |
| │ ├── apps.py | |
| │ ├── __init__.py | |
| │ ├── kafka_producer.py | |
| │ ├── migrations | |
| │ │ ├── 0001_initial.py | |
| │ │ ├── __init__.py | |
| │ ├── models.py | |
| │ ├── tests.py |
This file contains hidden or 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 json | |
| import sys | |
| from kafka import KafkaProducer | |
| from outboxexample import settings | |
| import signal | |
| producer = KafkaProducer(bootstrap_servers=[settings.KAFKA_HOST]) |
This file contains hidden or 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 django.contrib import admin | |
| from django.urls import path, include | |
| urlpatterns = [ | |
| path("admin/", admin.site.urls), | |
| path("", include("notes.urls")), | |
| ] |
This file contains hidden or 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 django.urls import path | |
| from . import views | |
| urlpatterns = [ | |
| path("notes", views.note_view, name="note_view"), | |
| ] |
This file contains hidden or 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 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 | |
This file contains hidden or 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 |