Async recognition pipeline:
- POST /ai/recognize-dish → 202 {job_id, queue_position, estimated_seconds}
- GET /ai/jobs/{id}/stream — SSE stream: queued → processing → done/failed
- Kafka topics: ai.recognize.paid (3 partitions) + ai.recognize.free (1 partition)
- 5-worker WorkerPool with priority loop (paid consumers first)
- SSEBroker via PostgreSQL LISTEN/NOTIFY
- Kafka adapter migrated from franz-go to Watermill (watermill-kafka/v2)
- Docker Compose: added Kafka + Zookeeper + kafka-init service
- Flutter: recognition_service.dart uses SSE; home_screen shows live job status
Remove google/wire (archived):
- Deleted wire.go (wireinject spec) and wire_gen.go
- Added cmd/server/init.go — plain Go manual DI, same initApp() logic
- Removed github.com/google/wire from go.mod
Consolidate migrations:
- Merged 001_initial_schema + 002_seed_data + 003_recognition_jobs into single 001_initial_schema.sql
- Deleted 002_seed_data.sql and 003_recognition_jobs.sql
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
package kafka
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/ThreeDotsLabs/watermill"
|
|
"github.com/ThreeDotsLabs/watermill/message"
|
|
wmkafka "github.com/ThreeDotsLabs/watermill-kafka/v2/pkg/kafka"
|
|
)
|
|
|
|
// Producer wraps a Watermill Kafka publisher for publishing messages to Kafka topics.
|
|
type Producer struct {
|
|
publisher message.Publisher
|
|
}
|
|
|
|
// NewProducer creates a Producer connected to the given brokers.
|
|
func NewProducer(brokers []string) (*Producer, error) {
|
|
publisher, createError := wmkafka.NewPublisher(
|
|
wmkafka.PublisherConfig{
|
|
Brokers: brokers,
|
|
Marshaler: wmkafka.DefaultMarshaler{},
|
|
},
|
|
watermill.NopLogger{},
|
|
)
|
|
if createError != nil {
|
|
return nil, createError
|
|
}
|
|
return &Producer{publisher: publisher}, nil
|
|
}
|
|
|
|
// Publish writes a single message to the named topic.
|
|
// The context parameter is accepted for interface compatibility but is not forwarded
|
|
// to the Watermill publisher, which does not accept a context.
|
|
func (producer *Producer) Publish(_ context.Context, topic, jobID string) error {
|
|
msg := message.NewMessage(watermill.NewUUID(), []byte(jobID))
|
|
return producer.publisher.Publish(topic, msg)
|
|
}
|
|
|
|
// Close shuts down the underlying Kafka publisher.
|
|
func (producer *Producer) Close() {
|
|
_ = producer.publisher.Close()
|
|
}
|