This microservice generates log messages and sends them to Kafka when its api is called .
The service produces a log message every 5 seconds in the following format and sends it to Kafka:
- Java 17+
- Apache Kafka
- Maven
- Docker (optional, for running Kafka)
create docker-compose.yml like following
services:
zookeeper:
image: confluentinc/cp-zookeeper:latest
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ports:
- "2181:2181"
kafka:
image: confluentinc/cp-kafka:latest
depends_on:
- zookeeper
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
ports:
- "9092:9092"
redis:
image: redis:latest
ports:
- "6379:6379"
command: redis-server --appendonly yes
Go to docker-compose.yml location and run the following.
docker-compose up -d
kafka-topics --create --topic log-topic --bootstrap-server localhost:9092 --partitions 5 --replication-factor 1
mvn spring-boot:run
curl -X GET http://localhost:8082/producer/send
{
"eventId": "<UUID>",
"payload": "Log event with ID <UUID>",
"timestamp": "<Timestamp>"
}