Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ If the topic is configured to use `LOG_APPEND_TIME`, the user-specified timestam
The `metrics` and `partitionsFor` methods delegate to the same methods on the underlying javadoc:org.apache.kafka.clients.producer.Producer[].
The `execute` method provides direct access to the underlying javadoc:org.apache.kafka.clients.producer.Producer[].

[NOTE]
====
When sending messages from Spring components, avoid using `@PostConstruct` methods if relying on automatic topic creation via `NewTopic` beans.
`@PostConstruct` runs before the application context is fully ready, which may cause `UnknownTopicOrPartitionException` on clean brokers.

Instead, consider these alternatives:

- Use an `ApplicationListener<ContextRefreshedEvent>` to ensure the context is fully refreshed before sending.
- Implement `SmartLifecycle` to start after the `KafkaAdmin` bean has completed its initialization.
- Pre-create topics externally.
====

To use the template, you can configure a producer factory and provide it in the template's constructor.
The following example shows how to do so:

Expand Down