Skip to main content
PreparationZone Logo
PrepZone

Spring Kafka: Template, Listeners, and Config

KafkaTemplate and @KafkaListener for VaultCommerce — Spring Boot 3 auto-configuration and JSON serialization.

Pass checkpoint below

Why this matters

  • KafkaTemplate provides sync/async send with built-in serializer configuration from application.yml.
  • @KafkaListener handles container lifecycle, concurrency, and ack modes.
  • Spring Boot 3.x auto-configures bootstrap servers from spring.kafka.bootstrap-servers.
  • Production VaultCommerce services are 100% Spring Kafka, not raw clients.
OrderServiceVaultCommerce
vaultcommerce.orders.placed.v1
InventoryConsumer
KafkaTemplate publishes to a topic. @KafkaListener consumes from a consumer group.

KafkaTemplate and producers

kafkaTemplate.send(topic, key, value) uses configured ProducerFactory. DefaultKafkaProducerFactory shares one producer per config. VaultCommerce defines multiple templates only when serialization differs (Avro vs JSON).

Key points

  • KafkaTemplate — Spring wrapper for producer send operations
  • @KafkaListener — declarative consumer endpoint
  • ConcurrentKafkaListenerContainerFactory — thread pool per listener
  • AckMode — RECORD, BATCH, MANUAL, MANUAL_IMMEDIATE
  • *spring.kafka. ** — Boot centralized configuration properties

The rest of this guide is part of Pro

Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.

Still to come · 2 sections

  • @KafkaListener configuration
  • VaultCommerce rollout checklist

Test yourself

Answer these before moving on — recall is what makes it stick.