Spring boot challenge:
-
download apache kafka locally, (just need to unzip) and run it (zookeeper & kafka servers)
-
create 1 kafka topic called "novice-players"
-
create the controllers, services, repositories and entities needed to do the following:
- a POST endpoint that receives an array of players
{
"players": [
{
"name": "Sub zero",
"type": "expert"
},
{
"name": "Scorpion",
"type": "novice"
},
{
"name": "Reptile",
"type": "meh"
}
]
}- for each "player" object you need to check its "type" property
- if it is "expert" you need to store the player in a H2 database.
- if it is "novice" you need to send that object via a kafka event to the "novice-players" topic
- if the type does not fit one of the above, you will let the user know in the endpoint response the response for the above payload would be:
{
"result": [
"player Sub zero stored in DB",
"player Scorpion sent to Kafka topic",
"player Reptile did not fit"
]
}- Git
- Java 15+
- Maven 3.6.1+
- Docker 20.10.3+
- Docker Compose 1.24.0+
| Service Name | Version |
|---|---|
| Zookeeper | 6.10.0 |
| Kafka | 6.10.0 |
| H2 database | 1.4.199 |
Build project
mvn clean installor
./mvnw clean installStart services
docker-compose up -dThe project will create the topic novice-players, as it was configured to perform such action but if you want to create manually this is the command
docker-compose exec kafka kafka-topics --create --bootstrap-server \
localhost:9092 --replication-factor 1 --partitions 1 --topic novice-playersThere are two ways to consult the messages within the topic: Using the command:
docker-compose exec kafka kafka-console-consumer --bootstrap-server localhost:9092 --topic novice-players --from-beginningor
Using kafdrop
mvn spring-boot:run -P localor
./mvnw spring-boot:run -P localor
java -jar -Dspring.profiles.active=local target/demo-0.0.1-SNAPSHOT.jarAcess to swagger here!
