update spring-kafka project with support for multiple partitions and JSON serializer (#1472)

This commit is contained in:
Vivek Kumar
2017-03-24 02:20:30 +05:30
committed by Grzegorz Piwowarek
parent b01c2c5a94
commit e884e3f924
7 changed files with 228 additions and 16 deletions

View File

@@ -2,8 +2,28 @@
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 a topic named 'baeldung' is created manually.
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 1 --topic baeldung`<br>
`$ bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 5 --topic partitioned`<br>
`$ bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic filtered`<br>
`$ bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic greeting`<br>
Two listeners with group Ids **foo** and **bar** are configured. When run successfully, the *Hello World!* message will be received by both the listeners and logged on console.
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 Messasge in group 'foo': Hello, World!<br>
Received Messasge in group 'bar': Hello, World!
#### Message received from the 'baeldung' topic, with the partition info
>Received Messasge: Hello, World! from partition: 0
#### Message received from the 'partitioned' topic, only from specific partitions
>Received Message: Hello To Partioned Topic! from partition: 0<br>
Received Message: Hello To Partioned Topic! from partition: 3
#### Message received from the 'filtered' topic after filtering
>Recieved Message in filtered listener: Hello Baeldung!
#### Message (Serialized Java Object) received from the 'greeting' topic
>Recieved greeting message: Greetings, World!!