Giter VIP home page Giter VIP logo

bootique-kafka-examples's Introduction

verify

Bootique 3.x Kafka Examples

This is an example Bootique Kafka app with producer and consumer. Different Git branches contain example code for different versions of Bootique:

Prerequisites

To build and run the project, make sure you have the following installed on your machine, and then follow the steps below:

  • Docker
  • Java 11 or newer
  • Maven

Checkout

git clone [email protected]:bootique-examples/bootique-kafka-examples.git
cd bootique-kafka-examples

Start Kafka Locally

docker-compose -f docker-compose.yml up -d

Build and package

Run the following command to build the code and package the app:

mvn clean package

Run

The following command prints a help message with supported options:

java -jar target/bootique-kafka-examples-3.0.jar
NAME
      bootique-kafka-examples-3.0.jar

OPTIONS
      --config=yaml_location
           Specifies YAML config location, which can be a file path or a URL.

      --consumer
           Starts a Kafka consumer for the specified topic

      -h, --help
           Prints this message.

      -H, --help-config
           Prints information about application modules and their configuration options.

      -p, --producer
           Starts an interactive Kafka producer for the specified topic

      -t topic_name, --topic=topic_name
           Kafka topic name

So first, let's run a producer that will write to bq-kafka-example topic:

java -jar target/bootique-kafka-examples-3.0.jar --producer \
    --config=config.yml \
    --topic=bq-kafka-example 

This starts an interactive console app that allows you to type messages, one line at a time, that are sent to Kafka:

INFO  main i.b.k.c.p.DefaultKafkaProducerBuilder: Creating producer. Cluster: 127.0.0.1:9092.
INFO  main o.a.k.c.t.i.KafkaMetricsCollector: initializing Kafka metrics collector
INFO  main o.a.k.c.u.AppInfoParser: Kafka version: 3.7.0
INFO  main o.a.k.c.u.AppInfoParser: Kafka commitId: 2ae524ed625438c5
INFO  main o.a.k.c.u.AppInfoParser: Kafka startTimeMs: 1715466159773
(producer) bq-kafka-example > Hi!
(producer) bq-kafka-example > Hi again!

You can read these messages from the bq-kafka-example topic using Kafka standard console consumer, but let's start our own consumer. Open a new terminal window, change to bootique-kafka-examples/ directory, and run the same Java app, but with --consumer command:

java -jar target/bootique-kafka-examples-3.0.jar --consumer \
    --config=config.yml \
    --topic=bq-kafka-example

Now, return to the running producer window, and type more messages. All of them should be mirrored in the consumer command output. You can stop either producer or consumer with Ctrl-c.

bootique-kafka-examples's People

Contributors

andrus avatar stariy95 avatar elena-bondareva avatar dmitars avatar

Stargazers

 avatar

Watchers

 avatar James Cloos avatar  avatar Arseni Bulatski 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.