-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from RegioHelden/8-retry-dead-letter-queue
feat: add retry and dead letter topic behaviour, refs #8
- Loading branch information
Showing
30 changed files
with
1,692 additions
and
281 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Changelog | ||
|
||
## 0.2.0 (2024-09-05) | ||
* Add decorator for topic retry and dead letter topic, see `README.md` | ||
* Separate `Topic` class in to `TopicProducer` and `TopicConsumer` classes. |
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
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
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
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
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from enum import StrEnum | ||
|
||
|
||
class DeadLetterHeader(StrEnum): | ||
MESSAGE = "DEAD_LETTER_MESSAGE" | ||
DETAIL = "DEAD_LETTER_DETAIL" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import re | ||
from typing import TYPE_CHECKING | ||
|
||
from django_kafka import settings | ||
from django_kafka.dead_letter.headers import DeadLetterHeader | ||
from django_kafka.retry.topic import RetryTopicProducer | ||
from django_kafka.serialization import NoOpSerializer | ||
from django_kafka.topic import TopicProducer | ||
|
||
if TYPE_CHECKING: | ||
from confluent_kafka import cimpl | ||
|
||
|
||
class DeadLetterTopicProducer(TopicProducer): | ||
key_serializer = NoOpSerializer | ||
value_serializer = NoOpSerializer | ||
|
||
def __init__(self, group_id: str, msg: "cimpl.Message"): | ||
self.group_id = group_id | ||
self.msg = msg | ||
super().__init__() | ||
|
||
@classmethod | ||
def suffix(cls): | ||
return settings.DEAD_LETTER_TOPIC_SUFFIX | ||
|
||
@property | ||
def name(self) -> str: | ||
topic = self.msg.topic() | ||
|
||
if re.search(RetryTopicProducer.pattern(), topic): | ||
return re.sub(RetryTopicProducer.pattern(), self.suffix(), topic) | ||
return f"{self.group_id}.{topic}.{self.suffix()}" | ||
|
||
def produce_for(self, header_message, header_detail): | ||
headers = [ | ||
(DeadLetterHeader.MESSAGE, header_message), | ||
(DeadLetterHeader.DETAIL, header_detail), | ||
] | ||
self.produce( | ||
key=self.msg.key(), | ||
value=self.msg.value(), | ||
headers=headers, | ||
) |
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
Oops, something went wrong.