Coder Social home page Coder Social logo

kafka_spring_docker_2024's Introduction

kafka_spring_docker_2024

Run the following from the root dir:

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

kafka_spring_docker_2024's People

Contributors

thoughtscript avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.