Skip to content

Commit

Permalink
GH-3242: Clarify docs on custom Consumer/Producer factories
Browse files Browse the repository at this point in the history
Fixes: #3242

(cherry picked from commit 67bd8cf)
  • Loading branch information
sobychacko authored and spring-builds committed May 9, 2024
1 parent a63b04c commit 74d3193
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ The following Spring Boot example overrides the default factories:
[source, java]
----
@Bean
public ConsumerFactory<String, Thing> kafkaConsumerFactory(JsonDeserializer customValueDeserializer) {
public ConsumerFactory<?, ?> kafkaConsumerFactory(JsonDeserializer customValueDeserializer) {
Map<String, Object> properties = new HashMap<>();
// properties.put(..., ...)
// ...
Expand All @@ -175,7 +175,7 @@ public ConsumerFactory<String, Thing> kafkaConsumerFactory(JsonDeserializer cust
}
@Bean
public ProducerFactory<String, Thing> kafkaProducerFactory(JsonSerializer customValueSerializer) {
public ProducerFactory<?, ?> kafkaProducerFactory(JsonSerializer customValueSerializer) {
return new DefaultKafkaProducerFactory<>(properties.buildProducerProperties(),
new StringSerializer(), customValueSerializer);
}
Expand All @@ -185,6 +185,9 @@ public ProducerFactory<String, Thing> kafkaProducerFactory(JsonSerializer custom
Setters are also provided, as an alternative to using these constructors.
====

NOTE: When using Spring Boot and overriding the `ConsumerFactory` and `ProducerFactory` as shown above, wild card generic types need to be used with the bean method return type.
If concrete generic types are provided instead, then Spring Boot will ignore these beans and still use the default ones.

Starting with version 2.2, you can explicitly configure the deserializer to use the supplied target type and ignore type information in headers by using one of the overloaded constructors that have a boolean `useHeadersIfPresent` argument (which is `true` by default).
The following example shows how to do so:

Expand Down

0 comments on commit 74d3193

Please sign in to comment.