This is a simple Java Spring Boot application that serves as a Kafka Producer. It demonstrates how to send messages to a Kafka topic using the KafkaTemplate and Spring Kafka integration.
- Java 8 or higher installed on your machine.
- Apache Kafka broker running on
localhost:9092
. - PostgreSQL database installed and configured with the following credentials:
- Username:
postgres
- Password: Your_Password
- Database URL:
jdbc:postgresql://localhost:5432/
- Username:
- Clone the repository to your local machine.
- Ensure that Kafka is up and running on
localhost:9092
. - Set up the PostgreSQL database and update the credentials in
application.properties
:spring.datasource.username=postgres spring.datasource.password=your_password spring.datasource.url=jdbc:postgresql://localhost:5432/your_database_name
- Build the application using Maven:
mvn clean package
- Run the application:
java -jar target/kafka-producer-app.jar
- Health Check: To send a message to the Kafka topic, make a GET request to
/producer
with the message in the request body. The message will be sent to the Kafka topic defined in the configuration.
The application's configuration can be found in application.properties
. You can update the following properties as per your requirements:
spring.kafka.bootstrap-servers
: Comma-separated list of Kafka broker addresses.spring.kafka.producer.value-serializer
: Serializer class for the message value.spring.kafka.producer.key-serializer
: Serializer class for the message key.kafka.topic
: The name of the Kafka topic to which messages will be sent.
- The
ProducerService
class handles message sending to the Kafka topic using theKafkaTemplate
. - The
@PostConstruct
method inProducerService
automatically sends a test message to the Kafka topic on application startup.
- Emre Terzi
- GitHub: (https://github.com/emretterzi)