In this assignment, implement a public API that interacts with an internal addition service. The addition service performs the addition of two numbers and posts the results to a Kafka topic named addition-service.results. The task is to build a public-api service that provides two endpoints:
/api/add: This endpoint forwards requests to the internal addition service, which performs the addition and posts the result to Kafka. It responds synchronously with anasyncIdthat corresponds to the request./api/list-results: This endpoint fetches and returns a list of all calculation results from the Kafka topicaddition-service.results.
./public-api/: Place all implementation files for thepublic-apiservice in this folder. This folder should contain the code for both the/api/addand/api/list-resultsendpoints../addition-service/: Contains the source code for the internal addition service../docker-compose.yml: Describes the system architecture including the Kafka and Zookeeper services../public-api.yml: API specification for thepublic-apiservice../start.sh: Script to rebuild and start the system.
-
API Implementation (
public-api):- Implement the
/api/addendpoint to forward requests to the internal addition service and return anasyncId. - Implement the
/api/list-resultsendpoint to consume messages from the Kafka topicaddition-service.resultsand respond with a list of all results.
- Implement the
-
Kafka Integration:
- Use Kafka to fetch results from the
addition-service.resultstopic. - Implement a Kafka consumer in
public-apiservice to listen to this topic.
- Use Kafka to fetch results from the
-
Security and Code Quality:
- Ensure the API is secure and handles errors gracefully.
- Write clean and maintainable code, and adhere to best practices for performance and scalability.
-
Build and Start the System: Run the
start.shscript to rebuild and start the entire system. This will build the Docker images and start the containers as described indocker-compose.yml../start.sh