Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 0 additions & 45 deletions fastloom/signals/kafka/depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,63 +7,18 @@

if TYPE_CHECKING:
from faststream.confluent.fastapi import KafkaRouter
from faststream.confluent.publisher.producer import (
AsyncConfluentFastProducerImpl,
)
from faststream.confluent.response import KafkaPublishCommand


def get_kafka_router(settings: KafkaSettings) -> KafkaRouter:
# deferred: see docs/signals.md#ordering
from faststream.confluent.fastapi import KafkaRouter
from faststream.confluent.publisher.producer import (
AsyncConfluentFastProducerImpl,
)

_patch_real_tombstones(AsyncConfluentFastProducerImpl)

return KafkaRouter(
settings.KAFKA_URI,
schema_url="/kafkaapi",
)


def _patch_real_tombstones(
producer_cls: type[AsyncConfluentFastProducerImpl],
) -> None:
# NOTE: publish(None, ...) isn't a real Kafka tombstone - the codec
# turns None into b"", and compaction only reclaims a key on a literal
# null value (ag2ai/faststream#1967, fix pending: ag2ai/faststream#2932).
# Wraps .publish() in place, at the same deferred point get_kafka_router()
# imports from - see docs/signals.md#ordering.
if getattr(producer_cls, "_fastloom_real_tombstones", False):
return

original_publish = producer_cls.publish

async def publish(
self: AsyncConfluentFastProducerImpl, cmd: KafkaPublishCommand
):
if cmd.body is not None:
return await original_publish(self, cmd)

headers_to_send = {"content-type": "", **cmd.headers_to_publish()}
return await self._producer.producer.send( # noqa: SLF001
topic=cmd.destination,
value=None,
key=cmd.key,
partition=cmd.partition,
timestamp_ms=cmd.timestamp_ms,
headers=[
(i, (j or "").encode()) for i, j in headers_to_send.items()
],
no_confirm=cmd.no_confirm,
)

producer_cls.publish = publish
producer_cls._fastloom_real_tombstones = True


class KafkaSubscriber(SelfSustaining):
"""Owns the shared FastStream KafkaRouter singleton."""

Expand Down
2 changes: 1 addition & 1 deletion plugins/fastloom-sdk/.claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "fastloom-sdk",
"description": "Skills for services that consume the fastloom library \u2014 scaffold new services, add routes and RabbitMQ subscribers, audit settings.",
"version": "0.4.48",
"version": "0.4.49",
"author": {
"name": "aradng"
},
Expand Down
28 changes: 16 additions & 12 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "fastloom"
version = "0.4.48"
version = "0.4.49"
description = "Core package"
authors = []
readme = "README.md"
Expand Down Expand Up @@ -30,7 +30,7 @@ rabbit = [
]
kafka = [
"uvicorn",
"faststream[otel,confluent]",
"faststream[otel,confluent] @ git+https://github.com/ag2ai/faststream.git@9d54a6d80303443e32e132c19d002a715bf476e0",
"opentelemetry-instrumentation-confluent-kafka>=0.62b1,<0.64b0",
]
redis = [
Expand Down
Loading