This Springboot application is designed to update user information and integrate with Kafka for event processing. The application follows a series of steps to fetch user data from the GitHub API, create a payload, and store it in a database. It then utilizes Kafka to send the payload as an event named "UserInfoChanged" to the "users" topic.
-
Sending User Information Update Request
- Send a PUT request to the
/users/:user_idendpoint of the Springboot application to update user information.
- Send a PUT request to the
-
Fetching User Data
- The application initiates a GET request to the GitHub API, using the
user_idas a path parameter, to retrieve information starting from thesincevariable. - The application receives the next 30 users, starting from the given
sincevariable value. - From the response, the
user_nameis extracted from the first element, representing the user with the givenuser_id. - Three additional API calls are made to the GitHub API using the
user_nameto fetch the user's basic details, list of followers, and list of repositories. This is handled by theGitHubService.
- The application initiates a GET request to the GitHub API, using the
-
Creating the Payload
- Using the responses obtained from the previous API calls and the request body of the user request made in step 1, the application creates a payload.
- The payload is then stored in the database for further processing.
-
Triggering Kafka Event
- User sends a POST request to the
/produce/:user_idendpoint with an empty body. - The application retrieves the payload associated with the given
user_idfrom the request and sends it to theEventProducerServicefor further processing.
- User sends a POST request to the
-
Event Processing with Kafka
- When the
EventProducerServicereceives the payload, it creates aUserInfoChangedevent. - The event is then sent to the Kafka server using the "users" topic for further event processing.
- When the
-
Clone the project from GitHub:
git clone https://github.com/ShakyaPr/User-Info-Update-Springboot-App-Kafka.gitcd User-Info-Update-Springboot-App-Kafka/ -
Deploy PostgreSQL Database, Kafka Server, and Kafdrop using Docker:
docker run --name postgres -e POSTGRES_PASSWORD=admin12#$ -d -p 5432:5432 postgresocker run --net=host -p 2181:2181 -p 9092:9092 -e ADVERTISED_HOST=127.0.0.1 -e NUM_PARTITIONS=10 --name kafka_server johnnypark/kafka-zookeeper -
Ensure that port 8000 is available on your system.
-
Run the application:
./mvnw spring-boot:run
