Appendix B: Change History

B.1. What’s New in 2.8 Since 2.7

This section covers the changes made from version 2.7 to version 2.8. For changes in earlier version, see Change History.spring-doc.cn

B.1.1. Kafka Client Version

This version requires the 3.0.0 kafka-clientsspring-doc.cn

B.1.2. Package Changes

Classes and interfaces related to type mapping have been moved from …​support.converter to …​support.mapping.spring-doc.cn

B.1.3. Out of Order Manual Commits

The listener container can now be configured to accept manual offset commits out of order (usually asynchronously). The container will defer the commit until the missing offset is acknowledged. See Manually Committing Offsets for more information.spring-doc.cn

B.1.4. @KafkaListener Changes

It is now possible to specify whether the listener method is a batch listener on the method itself. This allows the same container factory to be used for both record and batch listeners.spring-doc.cn

See Batch Listeners for more information.spring-doc.cn

Batch listeners can now handle conversion exceptions.spring-doc.cn

RecordFilterStrategy, when used with batch listeners, can now filter the entire batch in one call. See the note at the end of Batch Listeners for more information.spring-doc.cn

The @KafkaListener annotation now has the filter attribute, to override the container factory’s RecordFilterStrategy for just this listener.spring-doc.cn

The @KafkaListener annotation now has the info attribute; this is used to populate the new listener container property listenerInfo. This is then used to populate a KafkaHeaders.LISTENER_INFO header in each record which can be used in RecordInterceptor, RecordFilterStrategy, or the listener itself. See Listener Info Header and Abstract Listener Container Properties for more information.spring-doc.cn

B.1.5. KafkaTemplate Changes

You can now receive a single record, given the topic, partition and offset. See Using KafkaTemplate to Receive for more information.spring-doc.cn

B.1.6. CommonErrorHandler Added

The legacy GenericErrorHandler and its sub-interface hierarchies for record an batch listeners have been replaced by a new single interface CommonErrorHandler with implementations corresponding to most legacy implementations of GenericErrorHandler. See Container Error Handlers and Migrating Custom Legacy Error Handler Implementations to CommonErrorHandler for more information.spring-doc.cn

B.1.7. Listener Container Changes

The interceptBeforeTx container property is now true by default.spring-doc.cn

The authorizationExceptionRetryInterval property has been renamed to authExceptionRetryInterval and now applies to AuthenticationException s in addition to AuthorizationException s previously. Both exceptions are considered fatal and the container will stop by default, unless this property is set.spring-doc.cn

B.1.8. Serializer/Deserializer Changes

The DelegatingByTopicSerializer and DelegatingByTopicDeserializer are now provided. See Delegating Serializer and Deserializer for more information.spring-doc.cn

B.1.9. DeadLetterPublishingRecover Changes

The property stripPreviousExceptionHeaders is now true by default.spring-doc.cn

There are now several techniques to customize which headers are added to the output record.spring-doc.cn

B.1.10. Retryable Topics Changes

Now you can use the same factory for retryable and non-retryable topics. See Specifying a ListenerContainerFactory for more information.spring-doc.cn

There’s now a manageable global list of fatal exceptions that will make the failed record go straight to the DLT. Refer to Exception Classifier to see how to manage it.spring-doc.cn

You can now use blocking and non-blocking retries in conjunction. See Combining Blocking and Non-Blocking Retries for more information.spring-doc.cn

The KafkaBackOffException thrown when using the retryable topics feature is now logged at DEBUG level. See Changing KafkaBackOffException Logging Level if you need to change the logging level back to WARN or set it to any other level.spring-doc.cn

B.2. Changes between 2.6 and 2.7

B.2.1. Kafka Client Version

This version requires the 2.7.0 kafka-clients. It is also compatible with the 2.8.0 clients, since version 2.7.1; see Override Spring Boot Dependencies.spring-doc.cn

B.2.2. Non-Blocking Delayed Retries Using Topics

This significant new feature is added in this release. When strict ordering is not important, failed deliveries can be sent to another topic to be consumed later. A series of such retry topics can be configured, with increasing delays. See Non-Blocking Retries for more information.spring-doc.cn

B.2.3. Listener Container Changes

The onlyLogRecordMetadata container property is now true by default.spring-doc.cn

A new container property stopImmediate is now available.spring-doc.cn

See Listener Container Properties for more information.spring-doc.cn

Error handlers that use a BackOff between delivery attempts (e.g. SeekToCurrentErrorHandler and DefaultAfterRollbackProcessor) will now exit the back off interval soon after the container is stopped, rather than delaying the stop.spring-doc.cn

Error handlers and after rollback processors that extend FailedRecordProcessor can now be configured with one or more RetryListener s to receive information about retry and recovery progress.spring-doc.cn

The RecordInterceptor now has additional methods called after the listener returns (normally, or by throwing an exception). It also has a sub-interface ConsumerAwareRecordInterceptor. In addition, there is now a BatchInterceptor for batch listeners. See Message Listener Containers for more information.spring-doc.cn

B.2.4. @KafkaListener Changes

You can now validate the payload parameter of @KafkaHandler methods (class-level listeners). See @KafkaListener @Payload Validation for more information.spring-doc.cn

You can now set the rawRecordHeader property on the MessagingMessageConverter and BatchMessagingMessageConverter which causes the raw ConsumerRecord to be added to the converted Message<?>. This is useful, for example, if you wish to use a DeadLetterPublishingRecoverer in a listener error handler. See Listener Error Handlers for more information.spring-doc.cn

You can now modify @KafkaListener annotations during application initialization. See @KafkaListener Attribute Modification for more information.spring-doc.cn

B.2.5. DeadLetterPublishingRecover Changes

Now, if both the key and value fail deserialization, the original values are published to the DLT. Previously, the value was populated but the key DeserializationException remained in the headers. There is a breaking API change, if you subclassed the recoverer and overrode the createProducerRecord method.spring-doc.cn

In addition, the recoverer verifies that the partition selected by the destination resolver actually exists before publishing to it.spring-doc.cn

B.2.6. ChainedKafkaTransactionManager is Deprecated

See Transactions for more information.spring-doc.cn

B.2.7. ReplyingKafkaTemplate Changes

There is now a mechanism to examine a reply and fail the future exceptionally if some condition exists.spring-doc.cn

Support for sending and receiving spring-messaging Message<?> s has been added.spring-doc.cn

See Using ReplyingKafkaTemplate for more information.spring-doc.cn

B.2.8. Kafka Streams Changes

By default, the StreamsBuilderFactoryBean is now configured to not clean up local state. See Configuration for more information.spring-doc.cn

B.2.9. KafkaAdmin Changes

New methods createOrModifyTopics and describeTopics have been added. KafkaAdmin.NewTopics has been added to facilitate configuring multiple topics in a single bean. See Configuring Topics for more information.spring-doc.cn

B.2.10. MessageConverter Changes

It is now possible to add a spring-messaging SmartMessageConverter to the MessagingMessageConverter, allowing content negotiation based on the contentType header. See Spring Messaging Message Conversion for more information.spring-doc.cn

B.2.11. Sequencing @KafkaListener s

B.2.12. ExponentialBackOffWithMaxRetries

A new BackOff implementation is provided, making it more convenient to configure the max retries. See ExponentialBackOffWithMaxRetries Implementation for more information.spring-doc.cn

B.2.13. Conditional Delegating Error Handlers

These new error handlers can be configured to delegate to different error handlers, depending on the exception type. See Delegating Error Handler for more information.spring-doc.cn

B.3. Changes between 2.5 and 2.6

B.3.1. Kafka Client Version

This version requires the 2.6.0 kafka-clients.spring-doc.cn

B.3.2. Listener Container Changes

The default EOSMode is now BETA. See Exactly Once Semantics for more information.spring-doc.cn

Various error handlers (that extend FailedRecordProcessor) and the DefaultAfterRollbackProcessor now reset the BackOff if recovery fails. In addition, you can now select the BackOff to use based on the failed record and/or exception.spring-doc.cn

You can now configure an adviceChain in the container properties. See Listener Container Properties for more information.spring-doc.cn

When the container is configured to publish ListenerContainerIdleEvent s, it now publishes a ListenerContainerNoLongerIdleEvent when a record is received after publishing an idle event. See Application Events and Detecting Idle and Non-Responsive Consumers for more information.spring-doc.cn

B.3.3. @KafkaListener Changes

When using manual partition assignment, you can now specify a wildcard for determining which partitions should be reset to the initial offset. In addition, if the listener implements ConsumerSeekAware, onPartitionsAssigned() is called after the manual assignment. (Also added in version 2.5.5). See Explicit Partition Assignment for more information.spring-doc.cn

Convenience methods have been added to AbstractConsumerSeekAware to make seeking easier. See Seeking to a Specific Offset for more information.spring-doc.cn

B.3.4. ErrorHandler Changes

Subclasses of FailedRecordProcessor (e.g. SeekToCurrentErrorHandler, DefaultAfterRollbackProcessor, RecoveringBatchErrorHandler) can now be configured to reset the retry state if the exception is a different type to that which occurred previously with this record.spring-doc.cn

B.3.5. Producer Factory Changes

You can now set a maximum age for producers after which they will be closed and recreated. See Transactions for more information.spring-doc.cn

You can now update the configuration map after the DefaultKafkaProducerFactory has been created. This might be useful, for example, if you have to update SSL key/trust store locations after a credentials change. See Using DefaultKafkaProducerFactory for more information.spring-doc.cn

B.4. Changes between 2.4 and 2.5

This section covers the changes made from version 2.4 to version 2.5. For changes in earlier version, see Change History.spring-doc.cn

B.4.1. Consumer/Producer Factory Changes

The default consumer and producer factories can now invoke a callback whenever a consumer or producer is created or closed. Implementations for native Micrometer metrics are provided. See Factory Listeners for more information.spring-doc.cn

You can now change bootstrap server properties at runtime, enabling failover to another Kafka cluster. See Connecting to Kafka for more information.spring-doc.cn

B.4.2. StreamsBuilderFactoryBean Changes

The factory bean can now invoke a callback whenever a KafkaStreams created or destroyed. An Implementation for native Micrometer metrics is provided. See KafkaStreams Micrometer Support for more information.spring-doc.cn

B.4.3. Kafka Client Version

This version requires the 2.5.0 kafka-clients.spring-doc.cn

B.4.4. Class/Package Changes

SeekUtils has been moved from the o.s.k.support package to o.s.k.listener.spring-doc.cn

B.4.5. Delivery Attempts Header

There is now an option to to add a header which tracks delivery attempts when using certain error handlers and after rollback processors. See Delivery Attempts Header for more information.spring-doc.cn

B.4.6. @KafkaListener Changes

Default reply headers will now be populated automatically if needed when a @KafkaListener return type is Message<?>. See Reply Type Message<?> for more information.spring-doc.cn

The KafkaHeaders.RECEIVED_MESSAGE_KEY is no longer populated with a null value when the incoming record has a null key; the header is omitted altogether.spring-doc.cn

@KafkaListener methods can now specify a ConsumerRecordMetadata parameter instead of using discrete headers for metadata such as topic, partition, etc. See Consumer Record Metadata for more information.spring-doc.cn

B.4.7. Listener Container Changes

The assignmentCommitOption container property is now LATEST_ONLY_NO_TX by default. See Listener Container Properties for more information.spring-doc.cn

The subBatchPerPartition container property is now true by default when using transactions. See Transactions for more information.spring-doc.cn

A new RecoveringBatchErrorHandler is now provided.spring-doc.cn

Static group membership is now supported. See Message Listener Containers for more information.spring-doc.cn

When incremental/cooperative rebalancing is configured, if offsets fail to commit with a non-fatal RebalanceInProgressException, the container will attempt to re-commit the offsets for the partitions that remain assigned to this instance after the rebalance is completed.spring-doc.cn

The default error handler is now the SeekToCurrentErrorHandler for record listeners and RecoveringBatchErrorHandler for batch listeners. See Container Error Handlers for more information.spring-doc.cn

You can now control the level at which exceptions intentionally thrown by standard error handlers are logged. See Container Error Handlers for more information.spring-doc.cn

The getAssignmentsByClientId() method has been added, making it easier to determine which consumers in a concurrent container are assigned which partition(s). See Listener Container Properties for more information.spring-doc.cn

You can now suppress logging entire ConsumerRecord s in error, debug logs etc. See onlyLogRecordMetadata in Listener Container Properties.spring-doc.cn

B.4.8. KafkaTemplate Changes

The KafkaTemplate can now maintain micrometer timers. See Monitoring for more information.spring-doc.cn

The KafkaTemplate can now be configured with ProducerConfig properties to override those in the producer factory. See Using KafkaTemplate for more information.spring-doc.cn

A RoutingKafkaTemplate has now been provided. See Using RoutingKafkaTemplate for more information.spring-doc.cn

You can now use KafkaSendCallback instead of ListenerFutureCallback to get a narrower exception, making it easier to extract the failed ProducerRecord. See Using KafkaTemplate for more information.spring-doc.cn

B.4.9. Kafka String Serializer/Deserializer

New ToStringSerializer/StringDeserializer s as well as an associated SerDe are now provided. See String serialization for more information.spring-doc.cn

B.4.10. JsonDeserializer

The JsonDeserializer now has more flexibility to determine the deserialization type. See Using Methods to Determine Types for more information.spring-doc.cn

B.4.11. Delegating Serializer/Deserializer

The DelegatingSerializer can now handle "standard" types, when the outbound record has no header. See Delegating Serializer and Deserializer for more information.spring-doc.cn

B.4.12. Testing Changes

The KafkaTestUtils.consumerProps() helper record now sets ConsumerConfig.AUTO_OFFSET_RESET_CONFIG to earliest by default. See JUnit for more information.spring-doc.cn

B.5. Changes between 2.3 and 2.4

B.5.1. Kafka Client Version

This version requires the 2.4.0 kafka-clients or higher and supports the new incremental rebalancing feature.spring-doc.cn

B.5.2. ConsumerAwareRebalanceListener

Like ConsumerRebalanceListener, this interface now has an additional method onPartitionsLost. Refer to the Apache Kafka documentation for more information.spring-doc.cn

Unlike the ConsumerRebalanceListener, The default implementation does not call onPartitionsRevoked. Instead, the listener container will call that method after it has called onPartitionsLost; you should not, therefore, do the same when implementing ConsumerAwareRebalanceListener.spring-doc.cn

See the IMPORTANT note at the end of Rebalancing Listeners for more information.spring-doc.cn

B.5.3. GenericErrorHandler

The isAckAfterHandle() default implementation now returns true by default.spring-doc.cn

B.5.4. KafkaTemplate

The KafkaTemplate now supports non-transactional publishing alongside transactional. See KafkaTemplate Transactional and non-Transactional Publishing for more information.spring-doc.cn

B.5.5. AggregatingReplyingKafkaTemplate

The releaseStrategy is now a BiConsumer. It is now called after a timeout (as well as when records arrive); the second parameter is true in the case of a call after a timeout.spring-doc.cn

See Aggregating Multiple Replies for more information.spring-doc.cn

B.5.6. Listener Container

The ContainerProperties provides an authorizationExceptionRetryInterval option to let the listener container to retry after any AuthorizationException is thrown by the KafkaConsumer. See its JavaDocs and Using KafkaMessageListenerContainer for more information.spring-doc.cn

B.5.7. @KafkaListener

The @KafkaListener annotation has a new property splitIterables; default true. When a replying listener returns an Iterable this property controls whether the return result is sent as a single record or a record for each element is sent. See Forwarding Listener Results using @SendTo for more informationspring-doc.cn

Batch listeners can now be configured with a BatchToRecordAdapter; this allows, for example, the batch to be processed in a transaction while the listener gets one record at a time. With the default implementation, a ConsumerRecordRecoverer can be used to handle errors within the batch, without stopping the processing of the entire batch - this might be useful when using transactions. See Transactions with Batch Listeners for more information.spring-doc.cn

B.5.8. Kafka Streams

The StreamsBuilderFactoryBean accepts a new property KafkaStreamsInfrastructureCustomizer. This allows configuration of the builder and/or topology before the stream is created. See Spring Management for more information.spring-doc.cn

B.6. Changes Between 2.2 and 2.3

This section covers the changes made from version 2.2 to version 2.3.spring-doc.cn

B.6.1. Tips, Tricks and Examples

A new chapter Tips, Tricks and Examples has been added. Please submit GitHub issues and/or pull requests for additional entries in that chapter.spring-doc.cn

B.6.2. Kafka Client Version

This version requires the 2.3.0 kafka-clients or higher.spring-doc.cn

B.6.3. Class/Package Changes

TopicPartitionInitialOffset is deprecated in favor of TopicPartitionOffset.spring-doc.cn

B.6.4. Configuration Changes

Starting with version 2.3.4, the missingTopicsFatal container property is false by default. When this is true, the application fails to start if the broker is down; many users were affected by this change; given that Kafka is a high-availability platform, we did not anticipate that starting an application with no active brokers would be a common use case.spring-doc.cn

B.6.5. Producer and Consumer Factory Changes

The DefaultKafkaProducerFactory can now be configured to create a producer per thread. You can also provide Supplier<Serializer> instances in the constructor as an alternative to either configured classes (which require no-arg constructors), or constructing with Serializer instances, which are then shared between all Producers. See Using DefaultKafkaProducerFactory for more information.spring-doc.cn

The same option is available with Supplier<Deserializer> instances in DefaultKafkaConsumerFactory. See Using KafkaMessageListenerContainer for more information.spring-doc.cn

B.6.6. Listener Container Changes

Previously, error handlers received ListenerExecutionFailedException (with the actual listener exception as the cause) when the listener was invoked using a listener adapter (such as @KafkaListener s). Exceptions thrown by native GenericMessageListener s were passed to the error handler unchanged. Now a ListenerExecutionFailedException is always the argument (with the actual listener exception as the cause), which provides access to the container’s group.id property.spring-doc.cn

Because the listener container has it’s own mechanism for committing offsets, it prefers the Kafka ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG to be false. It now sets it to false automatically unless specifically set in the consumer factory or the container’s consumer property overrides.spring-doc.cn

The ackOnError property is now false by default.spring-doc.cn

It is now possible to obtain the consumer’s group.id property in the listener method. See Obtaining the Consumer group.id for more information.spring-doc.cn

The container has a new property recordInterceptor allowing records to be inspected or modified before invoking the listener. A CompositeRecordInterceptor is also provided in case you need to invoke multiple interceptors. See Message Listener Containers for more information.spring-doc.cn

The ConsumerSeekAware has new methods allowing you to perform seeks relative to the beginning, end, or current position and to seek to the first offset greater than or equal to a time stamp. See Seeking to a Specific Offset for more information.spring-doc.cn

A convenience class AbstractConsumerSeekAware is now provided to simplify seeking. See Seeking to a Specific Offset for more information.spring-doc.cn

The ContainerProperties provides an idleBetweenPolls option to let the main loop in the listener container to sleep between KafkaConsumer.poll() calls. See its JavaDocs and Using KafkaMessageListenerContainer for more information.spring-doc.cn

When using AckMode.MANUAL (or MANUAL_IMMEDIATE) you can now cause a redelivery by calling nack on the Acknowledgment. See Committing Offsets for more information.spring-doc.cn

Listener performance can now be monitored using Micrometer Timer s. See Monitoring for more information.spring-doc.cn

The containers now publish additional consumer lifecycle events relating to startup. See Application Events for more information.spring-doc.cn

Transactional batch listeners can now support zombie fencing. See Transactions for more information.spring-doc.cn

The listener container factory can now be configured with a ContainerCustomizer to further configure each container after it has been created and configured. See Container factory for more information.spring-doc.cn

B.6.7. ErrorHandler Changes

The SeekToCurrentErrorHandler now treats certain exceptions as fatal and disables retry for those, invoking the recoverer on first failure.spring-doc.cn

The SeekToCurrentErrorHandler and SeekToCurrentBatchErrorHandler can now be configured to apply a BackOff (thread sleep) between delivery attempts.spring-doc.cn

Starting with version 2.3.2, recovered records' offsets will be committed when the error handler returns after recovering a failed record.spring-doc.cn

The DeadLetterPublishingRecoverer, when used in conjunction with an ErrorHandlingDeserializer, now sets the payload of the message sent to the dead-letter topic, to the original value that could not be deserialized. Previously, it was null and user code needed to extract the DeserializationException from the message headers. See Publishing Dead-letter Records for more information.spring-doc.cn

B.6.8. TopicBuilder

A new class TopicBuilder is provided for more convenient creation of NewTopic @Bean s for automatic topic provisioning. See Configuring Topics for more information.spring-doc.cn

B.6.9. Kafka Streams Changes

You can now perform additional configuration of the StreamsBuilderFactoryBean created by @EnableKafkaStreams. See Streams Configuration for more information.spring-doc.cn

A RecoveringDeserializationExceptionHandler is now provided which allows records with deserialization errors to be recovered. It can be used in conjunction with a DeadLetterPublishingRecoverer to send these records to a dead-letter topic. See Recovery from Deserialization Exceptions for more information.spring-doc.cn

The HeaderEnricher transformer has been provided, using SpEL to generate the header values. See Header Enricher for more information.spring-doc.cn

The MessagingTransformer has been provided. This allows a Kafka streams topology to interact with a spring-messaging component, such as a Spring Integration flow. See MessagingTransformer and See [Calling a Spring Integration Flow from a KStream] for more information.spring-doc.cn

B.6.10. JSON Component Changes

Now all the JSON-aware components are configured by default with a Jackson ObjectMapper produced by the JacksonUtils.enhancedObjectMapper(). The JsonDeserializer now provides TypeReference-based constructors for better handling of target generic container types. Also a JacksonMimeTypeModule has been introduced for serialization of org.springframework.util.MimeType to plain string. See its JavaDocs and Serialization, Deserialization, and Message Conversion for more information.spring-doc.cn

A ByteArrayJsonMessageConverter has been provided as well as a new super class for all Json converters, JsonMessageConverter. Also, a StringOrBytesSerializer is now available; it can serialize byte[], Bytes and String values in ProducerRecord s. See Spring Messaging Message Conversion for more information.spring-doc.cn

The JsonSerializer, JsonDeserializer and JsonSerde now have fluent APIs to make programmatic configuration simpler. See the javadocs, Serialization, Deserialization, and Message Conversion, and Streams JSON Serialization and Deserialization for more informaion.spring-doc.cn

B.6.11. ReplyingKafkaTemplate

When a reply times out, the future is completed exceptionally with a KafkaReplyTimeoutException instead of a KafkaException.spring-doc.cn

Also, an overloaded sendAndReceive method is now provided that allows specifying the reply timeout on a per message basis.spring-doc.cn

B.6.12. AggregatingReplyingKafkaTemplate

Extends the ReplyingKafkaTemplate by aggregating replies from multiple receivers. See Aggregating Multiple Replies for more information.spring-doc.cn

B.6.13. Transaction Changes

You can now override the producer factory’s transactionIdPrefix on the KafkaTemplate and KafkaTransactionManager. See transactionIdPrefix for more information.spring-doc.cn

B.6.14. New Delegating Serializer/Deserializer

The framework now provides a delegating Serializer and Deserializer, utilizing a header to enable producing and consuming records with multiple key/value types. See Delegating Serializer and Deserializer for more information.spring-doc.cn

B.6.15. New Retrying Deserializer

The framework now provides a delegating RetryingDeserializer, to retry serialization when transient errors such as network problems might occur. See Retrying Deserializer for more information.spring-doc.cn

B.7. Changes Between 2.1 and 2.2

B.7.1. Kafka Client Version

This version requires the 2.0.0 kafka-clients or higher.spring-doc.cn

B.7.2. Class and Package Changes

The ContainerProperties class has been moved from org.springframework.kafka.listener.config to org.springframework.kafka.listener.spring-doc.cn

The AckMode enum has been moved from AbstractMessageListenerContainer to ContainerProperties.spring-doc.cn

The setBatchErrorHandler() and setErrorHandler() methods have been moved from ContainerProperties to both AbstractMessageListenerContainer and AbstractKafkaListenerContainerFactory.spring-doc.cn

B.7.3. After Rollback Processing

A new AfterRollbackProcessor strategy is provided. See After-rollback Processor for more information.spring-doc.cn

B.7.4. ConcurrentKafkaListenerContainerFactory Changes

You can now use the ConcurrentKafkaListenerContainerFactory to create and configure any ConcurrentMessageListenerContainer, not only those for @KafkaListener annotations. See Container factory for more information.spring-doc.cn

B.7.5. Listener Container Changes

A new container property (missingTopicsFatal) has been added. See Using KafkaMessageListenerContainer for more information.spring-doc.cn

A ConsumerStoppedEvent is now emitted when a consumer stops. See Thread Safety for more information.spring-doc.cn

Batch listeners can optionally receive the complete ConsumerRecords<?, ?> object instead of a List<ConsumerRecord<?, ?>. See Batch Listeners for more information.spring-doc.cn

The DefaultAfterRollbackProcessor and SeekToCurrentErrorHandler can now recover (skip) records that keep failing, and, by default, does so after 10 failures. They can be configured to publish failed records to a dead-letter topic.spring-doc.cn

Starting with version 2.2.4, the consumer’s group ID can be used while selecting the dead letter topic name.spring-doc.cn

The ConsumerStoppingEvent has been added. See Application Events for more information.spring-doc.cn

The SeekToCurrentErrorHandler can now be configured to commit the offset of a recovered record when the container is configured with AckMode.MANUAL_IMMEDIATE (since 2.2.4).spring-doc.cn

B.7.6. @KafkaListener Changes

You can now override the concurrency and autoStartup properties of the listener container factory by setting properties on the annotation. You can now add configuration to determine which headers (if any) are copied to a reply message. See @KafkaListener Annotation for more information.spring-doc.cn

You can now use @KafkaListener as a meta-annotation on your own annotations. See @KafkaListener as a Meta Annotation for more information.spring-doc.cn

It is now easier to configure a Validator for @Payload validation. See @KafkaListener @Payload Validation for more information.spring-doc.cn

You can now specify kafka consumer properties directly on the annotation; these will override any properties with the same name defined in the consumer factory (since version 2.2.4). See Annotation Properties for more information.spring-doc.cn

B.7.7. Header Mapping Changes

Headers of type MimeType and MediaType are now mapped as simple strings in the RecordHeader value. Previously, they were mapped as JSON and only MimeType was decoded. MediaType could not be decoded. They are now simple strings for interoperability.spring-doc.cn

Also, the DefaultKafkaHeaderMapper has a new addToStringClasses method, allowing the specification of types that should be mapped by using toString() instead of JSON. See Message Headers for more information.spring-doc.cn

B.7.8. Embedded Kafka Changes

The KafkaEmbedded class and its KafkaRule interface have been deprecated in favor of the EmbeddedKafkaBroker and its JUnit 4 EmbeddedKafkaRule wrapper. The @EmbeddedKafka annotation now populates an EmbeddedKafkaBroker bean instead of the deprecated KafkaEmbedded. This change allows the use of @EmbeddedKafka in JUnit 5 tests. The @EmbeddedKafka annotation now has the attribute ports to specify the port that populates the EmbeddedKafkaBroker. See Testing Applications for more information.spring-doc.cn

B.7.9. JsonSerializer/Deserializer Enhancements

You can now provide type mapping information by using producer and consumer properties.spring-doc.cn

New constructors are available on the deserializer to allow overriding the type header information with the supplied target type.spring-doc.cn

The JsonDeserializer now removes any type information headers by default.spring-doc.cn

You can now configure the JsonDeserializer to ignore type information headers by using a Kafka property (since 2.2.3).spring-doc.cn

B.7.10. Kafka Streams Changes

The streams configuration bean must now be a KafkaStreamsConfiguration object instead of a StreamsConfig object.spring-doc.cn

The StreamsBuilderFactoryBean has been moved from package …​core to …​config.spring-doc.cn

The KafkaStreamBrancher has been introduced for better end-user experience when conditional branches are built on top of KStream instance.spring-doc.cn

B.7.11. Transactional ID

When a transaction is started by the listener container, the transactional.id is now the transactionIdPrefix appended with <group.id>.<topic>.<partition>. This change allows proper fencing of zombies, as described here.spring-doc.cn

B.8. Changes Between 2.0 and 2.1

B.8.1. Kafka Client Version

This version requires the 1.0.0 kafka-clients or higher.spring-doc.cn

The 1.1.x client is supported natively in version 2.2.spring-doc.cn

B.8.2. JSON Improvements

The StringJsonMessageConverter and JsonSerializer now add type information in Headers, letting the converter and JsonDeserializer create specific types on reception, based on the message itself rather than a fixed configured type. See Serialization, Deserialization, and Message Conversion for more information.spring-doc.cn

B.8.3. Container Stopping Error Handlers

Container error handlers are now provided for both record and batch listeners that treat any exceptions thrown by the listener as fatal/ They stop the container. See Handling Exceptions for more information.spring-doc.cn

B.8.4. Pausing and Resuming Containers

The listener containers now have pause() and resume() methods (since version 2.1.3). See Pausing and Resuming Listener Containers for more information.spring-doc.cn

B.8.5. Stateful Retry

Starting with version 2.1.3, you can configure stateful retry. See Stateful Retry for more information.spring-doc.cn

B.8.6. Client ID

Starting with version 2.1.1, you can now set the client.id prefix on @KafkaListener. Previously, to customize the client ID, you needed a separate consumer factory (and container factory) per listener. The prefix is suffixed with -n to provide unique client IDs when you use concurrency.spring-doc.cn

B.8.7. Logging Offset Commits

By default, logging of topic offset commits is performed with the DEBUG logging level. Starting with version 2.1.2, a new property in ContainerProperties called commitLogLevel lets you specify the log level for these messages. See Using KafkaMessageListenerContainer for more information.spring-doc.cn

B.8.8. Default @KafkaHandler

Starting with version 2.1.3, you can designate one of the @KafkaHandler annotations on a class-level @KafkaListener as the default. See @KafkaListener on a Class for more information.spring-doc.cn

B.8.9. ReplyingKafkaTemplate

Starting with version 2.1.3, a subclass of KafkaTemplate is provided to support request/reply semantics. See Using ReplyingKafkaTemplate for more information.spring-doc.cn

B.8.10. ChainedKafkaTransactionManager

Version 2.1.3 introduced the ChainedKafkaTransactionManager. (It is now deprecated).spring-doc.cn

B.8.11. Migration Guide from 2.0

B.9. Changes Between 1.3 and 2.0

B.9.1. Spring Framework and Java Versions

The Spring for Apache Kafka project now requires Spring Framework 5.0 and Java 8.spring-doc.cn

B.9.2. @KafkaListener Changes

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 Forwarding Listener Results using @SendTo for more information.spring-doc.cn

B.9.3. Message Listeners

Message listeners can now be aware of the Consumer object. See Message Listeners for more information.spring-doc.cn

B.9.4. Using ConsumerAwareRebalanceListener

Rebalance listeners can now access the Consumer object during rebalance notifications. See Rebalancing Listeners for more information.spring-doc.cn

B.10. Changes Between 1.2 and 1.3

B.10.1. Support for Transactions

The 0.11.0.0 client library added support for transactions. The KafkaTransactionManager and other support for transactions have been added. See Transactions for more information.spring-doc.cn

B.10.2. Support for Headers

The 0.11.0.0 client library added support for message headers. These can now be mapped to and from spring-messaging MessageHeaders. See Message Headers for more information.spring-doc.cn

B.10.3. Creating Topics

The 0.11.0.0 client library provides an AdminClient, which you can use to create topics. The KafkaAdmin uses this client to automatically add topics defined as @Bean instances.spring-doc.cn

B.10.4. Support for Kafka Timestamps

KafkaTemplate now supports an 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 Using KafkaTemplate, @KafkaListener Annotation, and Testing Applications for more details.spring-doc.cn

B.10.5. @KafkaListener Changes

You can now configure a KafkaListenerErrorHandler to handle exceptions. See Handling Exceptions for more information.spring-doc.cn

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 values for listeners. To restore the previous behavior of using the factory configured group.id, set the idIsGroup property on the annotation to false.spring-doc.cn

B.10.6. @EmbeddedKafka Annotation

For convenience, a test class-level @EmbeddedKafka annotation is provided, to register KafkaEmbedded as a bean. See Testing Applications for more information.spring-doc.cn

B.10.7. Kerberos Configuration

Support for configuring Kerberos is now provided. See JAAS and Kerberos for more information.spring-doc.cn

B.11. Changes Between 1.1 and 1.2

This version uses the 0.10.2.x client.spring-doc.cn

B.12. Changes Between 1.0 and 1.1

B.12.1. Kafka Client

This version uses the Apache Kafka 0.10.x.x client.spring-doc.cn

B.12.2. Batch Listeners

Listeners can be configured to receive the entire batch of messages returned by the consumer.poll() operation, rather than one at a time.spring-doc.cn

B.12.3. Null Payloads

Null payloads are used to “delete” keys when you use log compaction.spring-doc.cn

B.12.4. Initial Offset

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.spring-doc.cn

B.12.5. Seek

You can now seek the position of each topic or partition. You can use this 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 Seeking to a Specific Offset for more information.spring-doc.cn