Skip to content

yusufoglu218/log-producer-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Log Producer Microservice

This microservice generates log messages and sends them to Kafka when its api is called .

📌 Project Description

The service produces a log message every 5 seconds in the following format and sends it to Kafka:

Requirement

  • Java 17+
  • Apache Kafka
  • Maven
  • Docker (optional, for running Kafka)

To install Kafka and Redis with docker-compose file

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

Create Kafka topic

kafka-topics --create --topic log-topic --bootstrap-server localhost:9092 --partitions 5 --replication-factor 1

🚀 Run the Application

mvn spring-boot:run

To call the service

curl -X GET http://localhost:8082/producer/send

The message to be sent to the Kafka

{
  "eventId": "<UUID>",
  "payload": "Log event with ID <UUID>",
  "timestamp": "<Timestamp>"
}

About

The microservice sends messages to the Kafka

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages