A microservice that translates document titles using Google's Gemini API as part of the Document Management System.
- Translation of document titles from English to Spanish
- Communication with Document Service via Kafka
- Integration with Google's Gemini API
- Error handling with automatic retries
- Logging for monitoring
- REST API for direct translation requests
- Java 17
- Spring Boot 3.2.0
- Spring Kafka for message processing
- Google Gemini API for translations
- Maven for dependency management and builds
- Java 17 or higher
- Maven 3.6+
- Running Kafka instance (local or remote)
- Google Gemini API key
- Clone the repository
- Create a
.env
file in the project root with your Gemini API key:GEMINI_API_KEY=your_api_key_here
- Build the project:
mvn clean install
- Run the service:
mvn spring-boot:run
The service runs on port 8083 by default and connects to Kafka on localhost:9092. You can modify these settings in the application.yml
file.
The service uses the following Kafka topics:
- translation-topic: Receives translation requests from Document Service
- document.translation.response: Sends translation results back to Document Service
For direct testing without using Kafka:
POST /api/translate
This endpoint is accessible through the API Gateway at http://localhost:8083/api/translate
.
Example request:
curl -X POST http://localhost:8083/api/translate \
-H "Content-Type: application/json" \
-d '{"title":"Annual Financial Report", "sourceLanguage":"en", "targetLanguage":"es"}'
- Document Service publishes a message to
translation-topic
with document ID and title - Translation Service consumes the message
- Translation Service calls Gemini API to translate the title
- Translation Service sends the translated title back to Document Service via
document.translation.response
- Document Service updates the document with the translated title
Name | Description | Required |
---|---|---|
GEMINI_API_KEY | Google Gemini API key | Yes |
SPRING_KAFKA_BOOTSTRAP_SERVERS | Kafka broker addresses | No (default: localhost:9092) |