Git Product home page Git Product logo

java-kafka-example's Introduction

Java Kafka Example

Sample project demonstrating Kafka usage with Java

  • kafka-basics - demonstrates basic producer and consumer usage
  • kafka-producer-twitter - demonstrates the producer which reads and produces twitter tweets
  • kafka-consumer-elasticsearch - demonstrates the consumer which reads and stores twitters tweets in elasticsearch
  • kafka-streams-filter-tweets - demonstrates kafka streams which filter twitter tweets
  • kafka-spring-basics - demonstrates kafka basics usage with spring framework
  • kafka-spring-twitter - demonstrates kafka twitter and elasticsearch usage with spring framework

CLI Commands

This section describes frequently used Kafka CLI commands.

Start Kafka

# Start ZooKeeper server
bin/zookeeper-server-start.sh config/zookeeper.properties

# Start Kafka server, note that ZooKeeper server must be running
bin/kafka-server-start.sh config/server.properties

Kafka Topics CLI

# Create a Kafka topic
bin/kafka-topics.sh --bootstrap-server localhost:9092 --topic demo-topic --create --partitions 3 --replication-factor 1

# List all Kafka topics
bin/kafka-topics.sh --bootstrap-server localhost:9092 --list

# Show the description of the Kafka topic
bin/kafka-topics.sh --bootstrap-server localhost:9092 --topic demo-topic --describe

# Delete the Kafka topic
bin/kafka-topics.sh --bootstrap-server localhost:9092 --topic demo-topic --delete

Kafka Console Producer CLI

# Start console producer
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic demo-topic

# Start console producer with additional properties
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic demo-topic --producer-property acks=all

# Start console producer with keys
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic demo-topic --property parse.key=true --property key.separator=,

Kafka Console Consumer CLI

# Start console consumer
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic demo-topic

# Start console consumer and read from the beginning
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic demo-topic --from-beginning

# Start console consumer with keys
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic demo-topic --from-beginning --property print.key=true --property key.separator=,

# Start console consumer as a part of the group
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic demo-topic --group demo-consumer-group

Kafka Consumer Groups CLI

# List all consumer groups
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --list

# Show the description of the Kafka consumer group
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group demo-consumer-group

# Reset offsets of the consumer group
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group demo-consumer-group --reset-offsets --to-earliest --execute --topic demo-topic

# Shift offsets of the consumer group
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group demo-consumer-group --reset-offsets --shift-by -2 --execute --topic demo-topic

java-kafka-example's People

Contributors

yoh0xff 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.