Skip to content

Latest commit

 

History

History
134 lines (84 loc) · 5.59 KB

spring-kafka-core.md

File metadata and controls

134 lines (84 loc) · 5.59 KB

Spring Kafka Core


Kafka Console Scripts

{::options parse_block_html="true" /}

Click to expand!

Go to kafka console (terminal).
If you are using docker, type docker exec -it [kafka-container-name] bash
For container name, you can get it by typing docker ps

# Hello Kafka
kafka-topics.sh --bootstrap-server localhost:9092 --create --partitions 1 --topic t-hello


# Consumer is Real Time
kafka-topics.sh --bootstrap-server localhost:9092 --create --partitions 1 --topic t-fixedrate
kafka-topics.sh --bootstrap-server localhost:9092 --create --partitions 1 --topic t-fixedrate-2


# Producing Message With Key
kafka-topics.sh --bootstrap-server localhost:9092 --create --partitions 3 --topic t-multi-partitions
kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic t-multi-partitions --offset earliest --partition 0
kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic t-multi-partitions --offset earliest --partition 1
kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic t-multi-partitions --offset earliest --partition 2


# Multiple Consumers
kafka-topics.sh --bootstrap-server localhost:9092 --alter --topic t-multi-partitions --partitions 4


# Producing JSON
kafka-topics.sh --bootstrap-server localhost:9092 --create --partitions 1 --topic t-employee
kafka-console-consumer.sh --bootstrap-server localhost:9092 --offset earliest --partition 0 --topic t-employee


# Customize JSON
kafka-topics.sh --bootstrap-server localhost:9092 --create --partitions 1 --topic t-employee-2
kafka-console-consumer.sh --bootstrap-server localhost:9092 --offset earliest --partition 0 --topic t-employee-2


# Consuming with Consumer Group
kafka-topics.sh --bootstrap-server localhost:9092 --create --partitions 1 --topic t-commodity
kafka-console-consumer.sh --bootstrap-server localhost:9092 --offset earliest --partition 0 --topic t-commodity
kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group cg-dashboard --describe
kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group cg-dashboard --execute --reset-offsets --to-offset 10 --topic t-commodity:0


# Handling Consumer Offset
kafka-console-consumer.sh --from-beginning --bootstrap-server localhost:9092 --property print.key=false --property print.value=false --topic t-counter --timeout-ms 5000 | tail -n 10|grep "Processed a total of"
kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group counter-group-fast --describe
kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group counter-group-slow --describe


# Rebalancing
kafka-topics.sh --bootstrap-server localhost:9092 --create --partitions 2 --topic t-rebalance-alpha
kafka-topics.sh --bootstrap-server localhost:9092 --create --partitions 2 --topic t-rebalance-beta
kafka-topics.sh --bootstrap-server localhost:9092 --alter --topic t-rebalance-alpha --partitions 5
kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic t-rebalance-alpha
kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic t-rebalance-beta


# Message Filter
kafka-topics.sh --bootstrap-server localhost:9092 --create --partitions 1 --topic t-location


# Idempotency
kafka-topics.sh --bootstrap-server localhost:9092 --create --partitions 1 --topic t-purchase-request
kafka-console-consumer.sh --bootstrap-server localhost:9092 --offset earliest --partition 0 --topic t-purchase-request

  
# Idempotency - Alternative
kafka-topics.sh --bootstrap-server localhost:9092 --create --partitions 1 --topic t-payment-request
kafka-console-consumer.sh --bootstrap-server localhost:9092 --offset earliest --partition 0 --topic t-payment-request

  
# Handling Exception on @KafkaListener
kafka-topics.sh --bootstrap-server localhost:9092 --create --partitions 1 --topic t-food-order
  
  
# Handling Exception - Global Error Handler
kafka-topics.sh --bootstrap-server localhost:9092 --create --partitions 1 --topic t-simple-number
kafka-topics.sh --bootstrap-server localhost:9092 --list | grep -E 'food|number'

  
# Retrying Consumer
kafka-topics.sh --bootstrap-server localhost:9092 --create --partitions 2 --topic t-image

  
# Handling Exception - Dead Letter Topic
kafka-topics.sh --bootstrap-server localhost:9092 --create --partitions 2 --topic t-invoice
kafka-topics.sh --bootstrap-server localhost:9092 --create --partitions 2 --topic t-invoice-dead
kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic t-invoice
kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic t-invoice-dead
  

# Non Blocking Retry
kafka-topics.sh --bootstrap-server localhost:9092 --create --partitions 2 --topic t-image-2
 
  
# Scheduling Consumer
kafka-topics.sh --bootstrap-server localhost:9092 --create --partitions 1 --topic t-general-ledger
kafka-console-consumer.sh --bootstrap-server localhost:9092 --from-beginning --topic t-general-ledger


# Order App - Test The App
kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic t-commodity-order


# Order App - Promotion Producer
kafka-topics.sh --bootstrap-server localhost:9092 --create --partitions 1 --topic t-commodity-promotion
kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic t-commodity-promotion

{::options parse_block_html="false" /}


Kafka Configuration Reference


Back to index