/kafka-example

Implementing producer/consumer for Kafka using Springbok

Primary LanguageJava

kafka-example

Implementing producer/consumer for Kafka using Springboot

  1. Download Kakfa 2.13-3.2.1 software

  2. Unzip the file

    tar -xvzf kafka_2.13-3.2.1.tgz
  3. Go to the kafka folder

    cd kafka_2.13-3.2.1
  4. Run zookeeper

    ./bin/zookeeper-server-start.sh config/zookeeper.properties
  5. Run Kafka server broker

    ./bin/kafka-server-start.sh config/server.properties
  6. Create a Java project with Spring Boot, for instance, using maven

    mvn archetype:generate \
       -DarchetypeArtifactId=maven-archetype-quickstart \
       -DgroupId=mx.isccarrasco.kafka \
       -DartifactId=kafka-sb-ms \
       -DarchetypeVersion=0.0.1-SNAPSHOT \
       -DinteractiveMode=false

    or for the case of SpringBoot, it highly recommended to use the https://start.spring.io

  7. Edit the application.properties file of the java project to assign the port of the kafka server

    spring.kafka.bootstrap-servers=localhost:9092
  8. Run consumer to read the information queued

    ./bin/kafka-console-consumer.sh --topic isccarrasco --from-beginning --bootstrap-server localhost:9092
  9. There is also available a REST API to send or add data to the queue

    http --json POST :8080/api/v1/messages message="api with kafka"