Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kafka_spring_docker_2024

Run the following from the root dir:

docker-compose up

# If using Docker Compose Engine V2:
docker compose up

Upon running that command you should see:

consumer_1  | 2024-05-03T23:57:07.747Z  INFO 60 --- [or-http-epoll-2] i.t.s.c.ReactiveRestController           : webclient message
producer_1  | 2024-05-03T23:57:07.749Z  INFO 60 --- [or-http-epoll-3] i.t.publisher.webclient.WebClient        : WebClient message sent!
producer_1  | 2024-05-03T23:57:12.335Z  INFO 60 --- [pool-5-thread-1] i.t.p.kafka.EmbeddedComponentClient      : Kafka message sent!
consumer_1  | 2024-05-03T23:57:12.338Z  INFO 60 --- [ntainer#0-0-C-1] i.t.s.kafka.EmbeddedComponentReceiver    : hello1
consumer_1  | 2024-05-03T23:57:12.338Z  INFO 60 --- [ntainer#0-0-C-1] i.t.s.kafka.EmbeddedComponentReceiver    : hello2
consumer_1  | 2024-05-03T23:57:12.338Z  INFO 60 --- [ntainer#0-0-C-1] i.t.s.kafka.EmbeddedComponentReceiver    : hello3
consumer_1  | 2024-05-03T23:57:12.339Z  INFO 60 --- [ntainer#0-0-C-1] i.t.s.kafka.EmbeddedComponentReceiver    : hello4
consumer_1  | 2024-05-03T23:57:12.752Z  INFO 60 --- [or-http-epoll-2] i.t.s.c.ReactiveRestController           : webclient message
producer_1  | 2024-05-03T23:57:12.753Z  INFO 60 --- [or-http-epoll-3] i.t.publisher.webclient.WebClient        : WebClient message sent!

The Producer app will repeatedly loop through and send a bunch of HTTP Webflux and Kafka messages to the test topic. The Consumer app will consume both kinds of messages using the simply wonderful (concise) EmbeddedComponentClient approach (great functionalitiy provided by the Spring Kafka libraries) and a ReactiveRestController!

Note: the whole cluster may take a few seconds to stabilize on app initialization, eventually you should just see a loop of messages like hte above.

Kafka Notes

Trying out:

  1. Kafka without Zookeeper! Using KRraft.
  2. Addressing Scenario 5 without doing the recommended ways (great article and super helpful - not sure exactly what's changed since 2020 but I got this working with two changes: networks in docker-compose.yml and spring.kafka.bootstrap-servers using the Docker-managed DNS kafka:9092 in application.properties).
  3. Containerizing, simplifying, and updating my 2022 examples from: java-reactive-pubsub .
  4. Also, curious about different ways to containerize Java Spring Boot apps - oftentimes people containerize just the .jar - is it easier to just supply the exploded file source code?

Resources and Links

  1. https://www.confluent.io/blog/kafka-client-cannot-connect-to-broker-on-aws-on-docker-etc/#scenario-5
  2. https://www.baeldung.com/java-kafka-bootstrap-server

About

Experiments with Kafka and Java Webflux

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages