The Spring for Apache Kafka project now requires Spring Framework 5.0 and Java 8.
You can now annotate @KafkaListener
methods (and classes, and @KafkaHandler
methods) with @SendTo
.
If the method returns a result, it is forwarded to the specified topic.
See the section called “Forwarding Listener Results using @SendTo” for more information.
Message listeners can now be aware of the Consumer
object.
See the section called “Message Listeners” for more information.
Rebalance listeners can now access the Consumer
object during rebalance notifications.
See the section called “Rebalance Listeners” for more information.
The 0.11.0.0 client library added support for transactions; the KafkaTransactionManager
and other support for transactions has been added.
See the section called “Transactions” for more information.
The 0.11.0.0 client library added support for message headers; these can now be mapped to/from spring-messaging
MessageHeaders
.
See Section 4.1.5, “Message Headers” for more information.
The 0.11.0.0 client library provides an AdminClient
which can be used to create topics.
The KafkaAdmin
uses this client to automatically add topics defined as @Bean
s.
KafkaTemplate
now supports API to add records with timestamps.
New KafkaHeaders
have been introduced regarding timestamp
support.
Also new KafkaConditions.timestamp()
and KafkaMatchers.hasTimestamp()
testing utilities have been added.
See the section called “KafkaTemplate”, the section called “@KafkaListener Annotation” and Section 4.3, “Testing Applications” for more details.
You can now configure a KafkaListenerErrorHandler
to handle exceptions.
See Section 4.1.7, “Handling Exceptions” for more information.
By default, the @KafkaListener
id
property is now used as the group.id
property, overriding the property configured in the consumer factory (if present).
Further, you can explicitly configure the groupId
on the annotation.
Previously, you would have needed a separate container factory (and consumer factory) to use different group.id
s for listeners.
To restore the previous behavior of using the factory configured group.id
, set the idIsGroup
property on the annotation to false
.
For convenience a test class level @EmbeddedKafka
annotation is provided with the purpose to register KafkaEmbedded
as a bean.
See Section 4.3, “Testing Applications” for more information.
Support for configuring Kerberos is now provided. See Section 4.1.8, “Kerberos” for more information.
Listeners can be configured to receive the entire batch of messages returned by the consumer.poll()
operation, rather than one at a time.
When explicitly assigning partitions, you can now configure the initial offset relative to the current position for the consumer group, rather than absolute or relative to the current end.
You can now seek the position of each topic/partition. This can be used to set the initial position during initialization when group management is in use and Kafka assigns the partitions. You can also seek when an idle container is detected, or at any arbitrary point in your application’s execution. See the section called “Seeking to a Specific Offset” for more information.