Skip to content

Path 9 · lesson 1 of 6

Intermediate30 minJava 21 · Spring Boot 3.5 (3.5.16 manages Spring for Apache Kafka 3.3.16 and kafka-clients 3.9.2) · Apache Kafka 4.x brokers in KRaft mode (apache/kafka 4.4.0 image locally). The client library is 3.9, not 4.x.

Spring Kafka setup: what Boot builds and what you configure

Wire a Spring Boot service to Kafka: the beans Boot creates from spring.kafka properties, producer and consumer configuration, topics as code, profiles and a local KRaft broker.

What you will learn

  • Name the five Kafka beans Spring Boot creates and say what makes each of them back off
  • Write an application.yml with common, producer, consumer and listener settings, and pass client properties that have no dedicated Spring Boot key
  • Declare topics with NewTopic beans and explain why production clusters usually switch off every form of automatic topic creation
  • Separate local and production settings with profiles without duplicating the shared configuration
  • Run a single-node KRaft broker locally with the official apache/kafka image and connect a Spring Boot service to it

Before you start

The concept

Spring for Apache Kafka (spring-kafka) is a library on top of the plain Kafka Java client. It does not replace the client: every send still goes through a KafkaProducer and every read through a KafkaConsumer. What it adds is lifecycle and threading. A factory owns the client objects, a template sends, and a listener container runs the poll loop and calls your method.

Spring Boot adds one more layer: with spring-kafka on the classpath it reads spring.kafka.* properties and creates those objects as beans. There is no Boot starter for Kafka; the dependency itself switches the auto-configuration on. Most services need no Kafka @Configuration class for clients at all.

Bean Boot createsWhat it doesBoot backs off when
ProducerFactory (DefaultKafkaProducerFactory)Creates and owns the producer. By default one producer is shared by all threadsYou declare any ProducerFactory bean
KafkaTemplateSends records through the producer factory and returns a future per sendYou declare any KafkaTemplate bean
ConsumerFactory (DefaultKafkaConsumerFactory)Creates a consumer for each listener thread from the consumer propertiesYou declare any ConsumerFactory bean
ConcurrentKafkaListenerContainerFactory named kafkaListenerContainerFactoryBuilds the listener container behind each @KafkaListener, using spring.kafka.listener.*A bean with that name exists
KafkaAdminCreates the topics you declare as NewTopic beans when the context startsYou declare a KafkaAdmin bean
Boot's Kafka auto-configuration. Each bean is conditional, so declaring your own replaces Boot's rather than adding to it.

Boot also enables @KafkaListener processing, so @EnableKafka is only needed in applications without Boot. The path's next lessons use these beans: the listener in depth, serialisation and error handling.

Why it exists

Without Spring you write the same code in every service: build a Properties object, create a KafkaProducer once and share it, start threads that each own a KafkaConsumer, loop on poll, commit offsets at the right moment, catch errors without killing the loop, and close everything in order on shutdown. Each of those steps has a well-known wrong version, such as a producer per request or a commit before processing.

The factories, template and container exist to make the correct version the default. Auto-configuration then removes the wiring code, which has a second benefit: configuration becomes data. The same jar runs against a laptop broker and a production cluster, and the difference is a profile and a few environment variables, not code.

The cost is that behaviour now comes from three layers, and you need to know which layer decided a value:

  1. Kafka client defaults, for every key nobody sets (for example max.poll.records 500).
  2. Spring Boot and Spring Kafka choices: Boot defaults the serializers and deserializers to the String ones and bootstrap-servers to localhost:9092; the listener container sets enable.auto.commit to false unless you set it yourself.
  3. Your properties: dedicated keys such as spring.kafka.producer.acks, and raw client keys under a properties map, which win when both are given.

How it works inside

From a YAML key to a client setting

Boot binds spring.kafka.* to a KafkaProperties object and builds three maps from it: producer, consumer and admin properties. Keys directly under spring.kafka (bootstrap servers, client id, security, SSL and the common properties map) go into all three. Keys under producer, consumer or admin go into that client type only and override the common value.

Boot has dedicated keys for the settings Kafka marks as high importance, a selection of the others, and those without a default. Everything else goes through the properties maps, which accept any client key. Write those keys in brackets in YAML so the dots stay part of the key: "[linger.ms]": 10. A value set this way overrides the dedicated Boot key for the same setting, so set each one in a single place.

You writeReachesExample
spring.kafka.<key>Producer, consumer and adminspring.kafka.bootstrap-servers
spring.kafka.properties.*Producer, consumer and admin, any client keysasl.mechanism
spring.kafka.producer.<key>The producer factoryspring.kafka.producer.acks
spring.kafka.producer.properties.*The producer factory, any producer keydelivery.timeout.ms, spring.json.add.type.headers
spring.kafka.consumer.<key>The consumer factoryspring.kafka.consumer.group-id
spring.kafka.consumer.properties.*The consumer factory, any consumer keypartition.assignment.strategy
spring.kafka.listener.*The listener container factory. These are Spring settings, not Kafka client settingsspring.kafka.listener.concurrency
spring.kafka.admin.*KafkaAdminspring.kafka.admin.auto-create
The listener block configures Spring's container (threads, acknowledgement mode). The consumer block configures the Kafka client the container uses.

When the clients are actually created

  • Admin: when the context starts, KafkaAdmin connects and creates missing NewTopic beans. If the broker is unreachable it logs the failure and the application keeps starting, unless spring.kafka.admin.fail-fast is true.
  • Consumers: each @KafkaListener container starts late in context startup and creates one consumer per thread. They join the group immediately.
  • Producer: created on the first send. A wrong bootstrap-servers therefore shows up at the first request, as a send that blocks for max.block.ms, not at startup.

Topics as code, and why auto-creation is switched off

There are three different mechanisms that can create a topic, and they are often confused.

MechanismControlled byWhat you get
Broker auto-creation on first useBroker auto.create.topics.enable (default true) together with the consumer's allow.auto.create.topics (default true)A topic with the broker defaults: num.partitions 1 and default.replication.factor 1 unless the operators changed them
NewTopic beans through KafkaAdminspring.kafka.admin.auto-create (default true)A topic with exactly the partitions, replication factor and topic configs you declared
Platform toolingYour organisation's pipeline (Terraform, an operator, a GitOps repository)Reviewed topics with owners, quotas and access rules

Broker auto-creation is the dangerous one. A typo in a topic name creates a new topic with one partition and no replication, the producer happily writes to it, and nobody reads it. A partition count chosen by accident is also hard to correct later, because adding partitions changes which partition a key maps to. Production clusters therefore usually set auto.create.topics.enable=false and restrict who may create topics with ACLs.

NewTopic beans are explicit and versioned with the code, which makes them a good fit for development, tests and teams that own their topics. Know what KafkaAdmin does with a topic that already exists: it leaves the configuration alone unless spring.kafka.admin.modify-topic-configs is true, but it does increase the partition count if the bean declares more partitions than the topic has. Raising a number in code is therefore a production change to key-to-partition mapping.

When to declare your own beans

Stay with properties

  • One cluster, one key type and one value format per direction
  • Settings that are plain client or container properties
  • Different values per environment: use profiles and environment variables
  • A cross-cutting bean Boot picks up by type: CommonErrorHandler, RecordMessageConverter, ConsumerAwareRebalanceListener

Declare a bean

  • A second listener container factory with another acknowledgement mode or batch delivery
  • Serializers built in code, for example with a customised ObjectMapper
  • A second cluster, or a second template with different serializers
  • Programmatic topic sets that depend on configuration

When you do declare a bean, remember the back-off rules in the first table. An extra listener container factory under another name is additive: Boot still creates kafkaListenerContainerFactory. A KafkaTemplate, ProducerFactory or ConsumerFactory bean of your own replaces Boot's, for every user of that type. For the factories the Spring reference adds a detail: declare the bean method with wildcard generic types, as Boot itself does, otherwise the pieces Boot still auto-configures may not find it. Boot's ConcurrentKafkaListenerContainerFactoryConfigurer lets a custom container factory start from everything in spring.kafka.listener.*, which the code below uses.

Architecture

Drawing diagram…

A flowchart. application.yml and the active profile are bound to KafkaProperties, which yields producer, consumer and admin properties. Producer properties feed the ProducerFactory, which feeds KafkaTemplate. Consumer properties feed the ConsumerFactory, which together with the listener settings feeds the listener container factory. Admin properties feed KafkaAdmin. Application code consists of a publisher that calls the template, a KafkaListener method invoked by the container, and NewTopic beans handed to KafkaAdmin. Template, container and admin all connect to the Kafka cluster.

flowchart TB
  Yml["application.yml plus the active profile"] --> KP["KafkaProperties"]
  KP --> PP["Producer properties"]
  KP --> CP["Consumer properties"]
  KP --> AP["Admin properties"]
  subgraph Auto["Beans created by Spring Boot"]
    PF["ProducerFactory"]
    KT["KafkaTemplate"]
    CF["ConsumerFactory"]
    LCF["kafkaListenerContainerFactory"]
    KA["KafkaAdmin"]
  end
  PP --> PF
  PF --> KT
  CP --> CF
  CF --> LCF
  KP --> LCF
  AP --> KA
  subgraph Yours["Your code"]
    Pub["Publisher calls KafkaTemplate send"]
    Lis["Method annotated KafkaListener"]
    NT["NewTopic beans"]
  end
  Pub --> KT
  LCF --> Lis
  NT --> KA
  KT --> Brk["Kafka cluster"]
  LCF --> Brk
  KA --> Brk
Properties become three client configurations; Boot builds five beans from them; your code touches only the template, the listener method and the topic declarations.
  • Everything in the Auto box is replaceable, but each bean has its own condition. Replacing one does not replace the others, which is how half-custom configurations end up with two different sets of settings.
  • The listener container factory takes input from two places: the consumer properties (Kafka client behaviour) and spring.kafka.listener.* (Spring's threads and acknowledgement mode).
  • KafkaAdmin is a separate client with its own connection. An application that is allowed to read and write a topic is not necessarily allowed to create it.
  • Your code depends on three small surfaces. That is what makes it testable against an embedded broker or Testcontainers with no code change; see testing and observability.

Message flow

Drawing diagram…

A sequence diagram of application startup. The application context initialises KafkaAdmin with the NewTopic beans. KafkaAdmin asks the broker to describe the topics, learns that orders.placed exists and payments.completed does not, and creates payments.completed with 6 partitions and replication factor 3. The context then starts the listener containers, which join the group payment-service, receive an assignment and begin polling. The context is ready before any producer exists. On the first send, KafkaTemplate creates the producer, fetches metadata, produces the record and receives the acknowledgement.

sequenceDiagram
  participant App as Application context
  participant Adm as KafkaAdmin
  participant Con as Listener container
  participant Tpl as KafkaTemplate
  participant B as Kafka broker
  App->>Adm: initialise with NewTopic beans
  Adm->>B: describe topics orders.placed and payments.completed
  B-->>Adm: orders.placed exists, payments.completed unknown
  Adm->>B: create payments.completed, 6 partitions, replication factor 3
  B-->>Adm: created
  App->>Con: start containers, late lifecycle phase
  Con->>B: join group payment-service
  B-->>Con: assignment orders.placed 0 to 5
  Con->>B: poll
  Note over App,Tpl: context is ready, no producer exists yet
  App->>Tpl: first send
  Tpl->>B: create producer, fetch metadata
  B-->>Tpl: partition leaders
  Tpl->>B: produce record
  B-->>Tpl: acknowledged
Startup order: topics, then listeners, and the producer only on first use.
  1. Topics are handled before listeners start, so a listener on a topic declared in the same application finds it.
  2. Listener containers start in a late lifecycle phase, after ordinary beans are ready, so the first record does not arrive in a half-built application.
  3. The producer is lazy. Health at startup says nothing about whether sends will work; the first send pays for the connection and metadata fetch.
  4. An existing topic is not recreated. Only a missing topic, or a lower partition count than declared, leads to a change on the cluster.

In a real system

Take the payment service of the example project. It consumes orders.placed in the group payment-service and publishes the outcome to payments.completed, keyed by order id so that everything about one order stays in one partition. Both topics have 6 partitions, replication factor 3 and min.insync.replicas=2 in production.

SettingLocal profileProduction profile
Brokerslocalhost:9092, one containerThree or more bootstrap addresses from the environment
SecurityPlaintextSASL_SSL with credentials from a secret store
TopicsCreated by NewTopic beans, replication factor 1Created by the platform pipeline; spring.kafka.admin.auto-create=false
A topic the service reads is missingStartup fails; start the owning service first or create the topic by handStartup fails, and the deployment with it (missing-topics-fatal=true)
First start of a new groupauto-offset-reset=earliestThe same: a new payment consumer must not skip existing orders
Listener threads13 per instance, two instances for six partitions
The shared application.yml holds everything that must not differ between environments: serializers, acks, idempotence, group id, acknowledgement mode.

The rule behind the split: guarantees are shared, addresses and sizes are per environment. If acks or the acknowledgement mode differed between local and production, tests on a laptop would prove nothing about production behaviour.

Java and Spring Boot

The setup of the payment service: build file, local broker, shared and per-profile configuration, topic declarations and one additional container factory. It was written against the Spring Boot 3.5 and Spring for Apache Kafka 3.3 references and has not been compiled or run in this environment.

pom.xml (dependencies)XML
<parent>  <groupId>org.springframework.boot</groupId>  <artifactId>spring-boot-starter-parent</artifactId>  <version>3.5.16</version>  <relativePath/></parent><properties>  <java.version>21</java.version></properties><dependencies>  <dependency>    <groupId>org.springframework.boot</groupId>    <artifactId>spring-boot-starter-web</artifactId>  </dependency>  <dependency>    <groupId>org.springframework.kafka</groupId>    <artifactId>spring-kafka</artifactId>  </dependency>  <dependency>    <groupId>org.springframework.boot</groupId>    <artifactId>spring-boot-starter-test</artifactId>    <scope>test</scope>  </dependency>  <dependency>    <groupId>org.springframework.kafka</groupId>    <artifactId>spring-kafka-test</artifactId>    <scope>test</scope>  </dependency></dependencies>

Why it is written this way

  • No version on spring-kafka. The Boot parent manages it (3.3.16 in Boot 3.5.16) together with the kafka-clients version it was built against (3.9.2).
  • There is no spring-boot-starter-kafka in Boot 3.x. The plain spring-kafka dependency is what activates the auto-configuration.
  • spring-boot-starter-web brings Jackson, which the JSON serializer and deserializer need.
  • The full build file of each service is in the example project.

Configuration

Defaults are from the Spring Boot 3.5 application properties appendix and the Boot source where the appendix lists none; Kafka client defaults are those of the 3.9 client and broker defaults those of Kafka 4.4.

spring.kafka.bootstrap-serversDefault none listed in the appendix; Boot's KafkaProperties initialises it to localhost:9092
What it does
Host and port pairs for the first connection. Applies to producer, consumer and admin unless overridden under producer, consumer or admin.
When to change it
Give several brokers. In production take it from the environment with no fallback, so a missing value stops the start.
spring.kafka.producer.key-serializer / value-serializerDefault none listed in the appendix; Boot's KafkaProperties uses StringSerializer for both
What it does
Serializer classes for record keys and values.
When to change it
Set them explicitly. With the String default, sending an object fails at the first send with a ClassCastException wrapped in a serialisation error.
spring.kafka.consumer.key-deserializer / value-deserializerDefault none listed in the appendix; Boot's KafkaProperties uses StringDeserializer for both
What it does
Deserializer classes for record keys and values.
When to change it
Wrap any deserializer that can fail in ErrorHandlingDeserializer so that a bad record is handled instead of blocking the partition.
spring.kafka.consumer.group-idDefault none
What it does
The consumer group for listeners that do not set one on the annotation.
When to change it
One group per service and purpose. A listener without any group id fails to start.
spring.kafka.consumer.auto-offset-resetDefault none in Spring Boot; Kafka client default latest
What it does
Where to start when the group has no committed offset for a partition, or the committed offset no longer exists: earliest, latest or none.
When to change it
Use earliest for services that must process everything. It is not a replay switch: it has no effect once offsets are committed.
spring.kafka.consumer.enable-auto-commitDefault none in Spring Boot; Spring's listener container sets enable.auto.commit=false unless you set it
What it does
Whether the Kafka client commits offsets on a timer in the background.
When to change it
Leave it unset. The container commits according to spring.kafka.listener.ack-mode, after your listener has run.
spring.kafka.producer.properties.* / spring.kafka.consumer.properties.* / spring.kafka.properties.*Default empty
What it does
Any Kafka client property (or Spring serializer property) by its real name. Values here override the dedicated Boot key for the same setting.
When to change it
Use bracket notation in YAML ("[linger.ms]": 10). Check the ProducerConfig values and ConsumerConfig values log blocks to confirm what was applied.
spring.kafka.listener.concurrencyDefault none in Spring Boot; the container default is 1
What it does
Number of consumer threads (and consumers) per @KafkaListener in this application instance.
When to change it
Size it so that instances multiplied by concurrency does not exceed the partition count; extra consumers sit idle.
spring.kafka.listener.missing-topics-fatalDefault false
What it does
Whether a listener container refuses to start when one of its topics does not exist.
When to change it
Set true where topics are provisioned outside the application.
spring.kafka.admin.auto-createDefault true
What it does
Whether KafkaAdmin creates NewTopic beans on the cluster during context start.
When to change it
Set false in environments where a pipeline owns topics or the application has no permission to create them.
spring.kafka.admin.fail-fastDefault false
What it does
Whether startup fails when KafkaAdmin cannot reach the broker.
When to change it
Useful locally and in tests. In production decide whether a service that also serves HTTP should refuse to start when Kafka is down.
spring.kafka.admin.modify-topic-configsDefault false
What it does
Whether KafkaAdmin changes the configuration of topics that already exist to match the NewTopic beans.
When to change it
Leave false unless the application is the single owner of the topic's configuration.
auto.create.topics.enable (broker)Default true
What it does
Whether the broker creates a topic when a client first asks for one that does not exist, using num.partitions (default 1) and default.replication.factor (default 1).
When to change it
Set false on any shared cluster. Create topics deliberately, with a chosen partition count and replication factor.
allow.auto.create.topics (consumer)Default true
What it does
Whether a consumer's subscription may trigger broker auto-creation. It only has an effect when the broker allows auto-creation.
When to change it
Set false under spring.kafka.consumer.properties if you cannot change the broker setting.

Hands-on exercise

Read your NewTopic declaration on a real cluster shape

See what the production topic declaration of this lesson means on three brokers, and why the same numbers cannot work on the one-broker local setup.

Steps · 0 of 6 done

Cluster explorer: the payment service's topics

Simulation · not a real cluster

Three brokers and the two topics exactly as the production profile expects them. Stop brokers and watch leaders, in-sync replicas and whether acks=all writes are accepted. This is a deterministic simulation, not a real cluster.

Take it further in the lab: Producer publishing messages

What can go wrong

Declaring one custom bean and losing Boot's configuration
Symptom
After adding a second KafkaTemplate for another value type, the original publisher fails at startup with no matching bean, or sends with different settings than application.yml says.
Cause
Boot's template is created only when no KafkaTemplate bean exists. The new bean made Boot back off, and a factory built by hand from a fresh map does not contain the spring.kafka.producer.* settings.
Fix
When you replace a bean, declare every variant you need explicitly, and build factories from Boot's KafkaProperties (for example buildProducerProperties()) plus your changes. Prefer properties, customisers and additional container factories, which do not replace anything.
The same setting in two places
Symptom
Changing spring.kafka.producer.acks has no effect; the ProducerConfig values log block shows another value.
Cause
The key is also set under spring.kafka.producer.properties (or the common spring.kafka.properties). Values in a properties map override the dedicated Boot key.
Fix
Set each Kafka setting once. Use the dedicated key where one exists and the properties map only for the rest.
Topics created by accident
Symptom
A topic with one partition and replication factor 1 exists that nobody declared; a service writes to it and no consumer ever reads the records.
Cause
A misspelt topic name, with broker auto.create.topics.enable left at true. The first metadata request created the topic with broker defaults.
Fix
Disable broker auto-creation, take topic names from configuration instead of repeating string literals, and set spring.kafka.listener.missing-topics-fatal=true.
Production replication settings on a single local broker
Symptom
Locally the application starts, but topic creation logs an InvalidReplicationFactorException, or every send fails with NotEnoughReplicasException after delivery.timeout.ms.
Cause
Replication factor 3 cannot be placed on one broker, and min.insync.replicas=2 can never be met by one replica.
Fix
Override replication factor and min.insync.replicas to 1 in the local profile, as this lesson does, or run three brokers locally.
A raised partition count applied by KafkaAdmin
Symptom
After a release that changed partitions from 6 to 12 in configuration, events for the same order start to appear out of order for a while.
Cause
KafkaAdmin increases the partition count of an existing topic when the NewTopic bean declares more. Keys now hash to different partitions, so old and new events for one key sit in different partitions.
Fix
Treat the partition count as an operational change with a migration plan, not a property edit. Where the pipeline owns topics, keep spring.kafka.admin.auto-create=false. See keys and partitioning.
Advertised listener that the client cannot reach
Symptom
The application connects to the bootstrap address, then logs repeated connection failures to another host name or to localhost, and sends time out.
Cause
After bootstrap, clients connect to the addresses the broker advertises. A broker in a container that advertises localhost:9092 is unreachable from another container; one that advertises its container name is unreachable from the host.
Fix
Advertise an address that is valid from where the client runs. For both host and container clients, configure two listeners with different advertised addresses, as in the image documentation's multi-listener example.

How to troubleshoot

Not sure which values the clients really run with

Check

The `ProducerConfig values:`, `ConsumerConfig values:` and `AdminClientConfig values:` blocks the Kafka client logs at INFO when each client is created
How to read it
They show the merged result of client defaults, Boot keys and properties overrides. A value you set that does not appear there was set under the wrong key or overridden. The producer block appears only after the first send.
Startup fails with an error that no group id was found for a listener

Check

`spring.kafka.consumer.group-id` in the active configuration, and the `groupId` and `id` attributes of the `@KafkaListener`
How to read it
A subscribing consumer needs a group. Set the property, or groupId on the annotation. If the property is set but only in a profile file, the profile is probably not active.
The application starts but never receives or sends anything, and the log repeats that a connection to a node could not be established

Check

docker exec --workdir /opt/kafka/bin -it broker ./kafka-broker-api-versions.sh --bootstrap-server localhost:9092
How to read it
If this works inside the container but the application cannot connect, compare spring.kafka.bootstrap-servers with the broker's advertised listeners and the published port. The host name in the log line is the advertised one.
Need to confirm what a topic really looks like on the cluster

Check

bin/kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic payments.completed
How to read it
Compare PartitionCount, ReplicationFactor and Configs with the NewTopic bean. A difference in configs on an existing topic is expected, because KafkaAdmin does not modify them by default.
A new consumer group starts and processes nothing although the topic has records

Check

bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group payment-service
How to read it
If CURRENT-OFFSET equals LOG-END-OFFSET right after the first start, the group began at the end: auto.offset.reset was latest. Setting earliest now changes nothing for this group, because offsets are already committed; reset them with --reset-offsets while the group is stopped.
Which profile and which configuration files were used?

Check

The startup log line `The following 1 profile is active: "prod"` and, with Actuator, the `/actuator/env` endpoint
How to read it
If the line says no active profile was set, only application.yml applied, which in this lesson means localhost:9092 and no topic overrides.

Key takeaways

  • spring-kafka wraps the Kafka client; Spring Boot builds ProducerFactory, KafkaTemplate, ConsumerFactory, the listener container factory and KafkaAdmin from spring.kafka.*.
  • Each auto-configured bean backs off separately when you declare your own. Add container factories freely; replace templates and factories only knowingly.
  • Any client setting without a dedicated Boot key goes under a properties map, and that map wins over the dedicated key.
  • Boot 3.5 runs a 3.9 client against 4.x brokers. Defaults belong to the client version, so write down the settings you rely on and read the config blocks in the log.
  • Declare topics deliberately, as NewTopic beans or in a pipeline, and switch off broker auto-creation. Remember that KafkaAdmin raises partition counts.
  • Share guarantees across environments and vary only addresses, security and sizes through profiles.
  • Admin and listeners connect at startup; the producer connects on the first send.

Practical check

Small scenarios, one decision each. Pick what you would do, then read why.

Scenario 1 of 3

A service uses Boot's auto-configured KafkaTemplate with JsonSerializer and acks=all from application.yml. A developer adds a @Bean KafkaTemplate<String, byte[]> built from a new DefaultKafkaProducerFactory with only bootstrap servers and ByteArraySerializer in its map, for one audit topic. After the release, order events fail to send with a serialisation error.

What happened?

Scenario 2 of 3

A new inventory service is deployed with group id inventory-service on a cluster where auto.create.topics.enable is true. Its listener is annotated with topics = "order.placed" (the real topic is orders.placed, 6 partitions). The service starts cleanly, reports healthy and processes nothing for two days.

Which combination would have turned this into a failed deployment?

Scenario 3 of 3

Locally you run the single-broker compose file. You start the service without a profile, so app.topics has replicas 3 and min-insync-replicas 2, and spring.kafka.admin.fail-fast is false. The application starts. The first payment result send blocks and then fails.

What is the most direct correction?

References

References: Spring Boot 3.5 reference: Messaging, Apache Kafka Support (auto-configuration, additional properties) ↗ · Spring Boot 3.5: Common application properties (spring.kafka.*) ↗ · Spring Boot 3.5: Managed dependency coordinates (spring-kafka 3.3.16, kafka-clients 3.9.2) ↗ · Spring for Apache Kafka 3.3 reference: Configuring Topics (KafkaAdmin, NewTopic, TopicBuilder) ↗ · Spring for Apache Kafka 3.3 reference: Message Listener Containers (enable.auto.commit, missingTopicsFatal) ↗ · Spring for Apache Kafka 3.3 reference: Serialization (overriding Boot's factories with wildcard generics) ↗ · Spring Boot 3.5 source: KafkaAutoConfiguration (bean conditions) ↗ · Apache Kafka official Docker image: usage and environment variables ↗ · Apache Kafka Docker image usage guide and example compose files ↗ · Apache Kafka 4.4: Broker configs (auto.create.topics.enable, num.partitions, default.replication.factor) ↗ · Apache Kafka 3.9: Consumer configs (defaults of the client Spring Boot 3.5 manages) ↗ · Report a problem