java-tutorials/spring-kafka
Muhammad Abdullah Azam Khan ef0b7ea20c Update KafkaApplication.java (#12424)
* Update KafkaApplication.java

Added partition offset to the listener so that it can start consuming the messages from the beginning of the topic.

* Revert "Update KafkaApplication.java"

This reverts commit 28801f85174af8bf2d2bb89e1fb39b52c49a6cf0.

* Counting Messages

1. Counting messages from Producer offset
2. Counting messages from Consumer
3. Rest APIs to view the count

* Refactoring

* Adding 3rd programmatic method to count number of messages in Kafka topic

* Removing irrelevant code

* Server port removed
2022-08-08 09:33:20 +05:30
..
src Update KafkaApplication.java (#12424) 2022-08-08 09:33:20 +05:30
README.md Update README.md 2021-12-23 01:58:49 +08:00
pom.xml [JAVA-8986] Upgrade spring-kafka to latest Boot version 2022-01-14 10:28:09 +00:00

README.md

Spring Kafka

This module contains articles about Spring with Kafka

Relevant articles

Intro

This is a simple Spring Boot app to demonstrate sending and receiving of messages in Kafka using spring-kafka.

As Kafka topics are not created automatically by default, this application requires that you create the following topics manually.

$ bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic baeldung
$ bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 5 --topic partitioned
$ bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic filtered
$ bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic greeting

When the application runs successfully, following output is logged on to console (along with spring logs):

Message received from the 'baeldung' topic by the basic listeners with groups foo and bar

Received Message in group 'foo': Hello, World!
Received Message in group 'bar': Hello, World!

Message received from the 'baeldung' topic, with the partition info

Received Message: Hello, World! from partition: 0

Message received from the 'partitioned' topic, only from specific partitions

Received Message: Hello To Partioned Topic! from partition: 0
Received Message: Hello To Partioned Topic! from partition: 3

Message received from the 'filtered' topic after filtering

Received Message in filtered listener: Hello Baeldung!

Message (Serialized Java Object) received from the 'greeting' topic

Received greeting message: Greetings, World!!