File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed
spring-kafka-docs/src/main/antora/modules/ROOT/pages/kafka Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change 4
4
If you define a `KafkaAdmin` bean in your application context, it can automatically add topics to the broker.
5
5
To do so, you can add a `NewTopic` `@Bean` for each topic to the application context.
6
6
Version 2.3 introduced a new class `TopicBuilder` to make creation of such beans more convenient.
7
+
8
+ [NOTE]
9
+ ====
10
+ When relying on topic auto-creation by declaring `NewTopic` beans, avoid producing
11
+ messages from `@PostConstruct` methods. `@PostConstruct` runs before
12
+ `KafkaAdmin` applies `NewTopic` declarations. On a clean broker, this may cause
13
+ `UnknownTopicOrPartitionException`.
14
+
15
+ Instead, consider:
16
+ - Using an `ApplicationListener<ContextRefreshedEvent>` to send after the context is fully refreshed.
17
+ - Implementing `SmartLifecycle` and starting after `KafkaAdmin`.
18
+ - Or pre-creating topics externally.
19
+ ====
20
+
7
21
The following example shows how to do so:
8
22
9
23
[tabs]
You can’t perform that action at this time.
0 commit comments