Add message queue / event-driven processing with Kafka#18
Merged
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Introduces a full message broker layer to decouple image ingestion from processing, following the existing Clean Architecture patterns. Uploads optionally publish processing tasks to Apache Kafka; standalone consumer workers pull tasks and process images asynchronously. The feature includes end-to-end OpenTelemetry metrics for broker operations and a Grafana dashboard section for monitoring the pipeline.
Version
2.2.3→2.3.0(MINOR — new feature, backward-compatible)What changed
Domain Layer
MessageBrokerabstract port withpublish(),consume(),close()methods and aMessagedataclassApplication Layer
UploadImageUseCaseextended with optional broker — publishes a processing event after persistingConsumeProcessingTasksUseCase— pulls messages from the queue and delegates toProcessImageUseCaseInfrastructure Layer
KafkaMessageBrokeradapter usingaiokafka(lazy producer/consumer initialization, consumer groups)InMemoryMessageBrokeradapter usingasyncio.Queuefor testing/local devbroker_messages_published_total,broker_messages_consumed_total,broker_publish_errors_total,broker_consume_errors_total,broker_consumer_processing_duration_secondsPresentation Layer
_broker()factory,get_consume_use_case(), upload wired with brokerbroker.close()Worker
Deployment
02a-kafka.yaml, 04a-worker-deployment.yaml,04b-worker-metrics-service.yamldemo.shupdated for Kafka + workerConfiguration
IMG_BROKER_ENABLEDfalseIMG_KAFKA_BOOTSTRAP_SERVERSlocalhost:9092IMG_KAFKA_CONSUMER_GROUPimage-processingIMG_WORKER_METRICS_PORT9090Files changed
33 files changed, +1312 −15 lines
mock_brokerfixtureTesting
Checklist
ruff check— all cleanmypy— no issuespytest— 282 tests passing[2.3.0]