附录 B: 变更历史

B.1. 2.8版本的新功能 自从2.7版本

此部分涵盖了从版本 2.7 到版本 2.8 的更改内容。对于更早版本的变更历史,请参见 变更历史.spring-doc.cadn.net.cn

B.1.1. Kafka 客户端版本

此版本需要 3.0.0 kafka-clientsspring-doc.cadn.net.cn

B.1.2. 包的更改

类型映射相关的类和接口已经从…​support.converter移至…​support.mappingspring-doc.cadn.net.cn

出顺序的手动提交

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.cadn.net.cn

B.1.4. @KafkaListener变更

现在可以在方法本身上指定监听器方法是否为批量监听器。 这使得同一个容器工厂可以用于记录和批量监听器的配置。spring-doc.cadn.net.cn

See 批处理监听器 以获取更多信息。spring-doc.cadn.net.cn

批处理监听器现在可以处理转换异常。spring-doc.cadn.net.cn

RecordFilterStrategy, 当与批处理监听器结合使用时,现在可以在一次调用中过滤整个批处理。 更多详细信息请参见批处理监听器一节末尾的备注。spring-doc.cadn.net.cn

The @KafkaListener 注解现在具有 filter 属性,用于覆盖此监听器容器工厂的 RecordFilterStrategyspring-doc.cadn.net.cn

The <code>0</code> annotation now has the <code>1</code> attribute; this is used to populate the new listener container property <code>2</code>. This is then used to populate a <code>3</code> header in each record which can be used in <code>4</code>, <code>5</code>, or the listener itself. See <a href=\"6\">Listener Info Header</a> and <a href=\"7\">Abstract Listener Container Properties</a> for more information.spring-doc.cadn.net.cn

B.1.5. KafkaTemplate变更

您现在可以基于主题、分区和偏移量来接收单条记录。
请参阅使用 KafkaTemplate 接收以获取更多信息。spring-doc.cadn.net.cn

B.1.6. CommonErrorHandler添加

The legacy GenericErrorHandler 和其子接口层次结构已替换为一个新的单一接口 CommonErrorHandler,该接口的实现对应于大多数现有的 GenericErrorHandler 的实现。 请参见 容器错误处理程序 以及 将自定义遗留错误处理程序实现实现迁移到 CommonErrorHandler 以获取更多详细信息。spring-doc.cadn.net.cn

B.1.7. 监听器容器变更

The interceptBeforeTx 容器属性现在默认为 truespring-doc.cadn.net.cn

The authorizationExceptionRetryInterval 属性已被重命名为 authExceptionRetryInterval,现在适用于除 AuthorizationException 之外的 AuthenticationException。 两种异常都被视为致命错误,默认情况下容器会停止运行,除非设置了该属性。spring-doc.cadn.net.cn

B.1.8. 序列化器/反序列化器变更

The DelegatingByTopicSerializerDelegatingByTopicDeserializer现在提供了。 见委托序列化器和反序列化器以获取更多信息。spring-doc.cadn.net.cn

B.1.9. DeadLetterPublishingRecover变更

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

现在有几种技术可以自定义添加到输出记录中的哪些标头。spring-doc.cadn.net.cn

B.1.10. 可重试主题的变更

现在您可以使用同一个工厂来处理可重试和不可重试的主题。 有关更多信息,请参阅指定ListenerContainerFactoryspring-doc.cadn.net.cn

现在有一个可管理的全局致命异常列表,失败记录将直接进入DLT。 查看异常分类器了解如何进行管理。spring-doc.cadn.net.cn

您现在可以同时使用阻塞和非阻塞重试。 请参阅 结合使用阻塞和非阻塞重试 以获取更多信息。spring-doc.cadn.net.cn

The KafkaBackOffException 抛出时现在记录为 DEBUG 级别,当使用可重试主题特性时。 如需将日志级别更改为 WARN 或设置为其他级别,请参阅 更改 KafkaBackOffException 日志级别spring-doc.cadn.net.cn

B.2. 2.6 和 2.7 之间的变更

B.2.1. Kafka 客户端版本

此版本需要2.7.0 kafka-clients。 它也与自2.7.1版本以来的2.8.0客户端兼容;请参阅 覆盖Spring Boot依赖项spring-doc.cadn.net.cn

B.2.2. 使用主题的非阻塞延迟重试

此重要新功能已在此版本中添加。 当严格顺序不重要时,失败的交付可以发送到另一个主题稍后被消费。 可以配置一系列这样的重试主题,并且具有递增的延迟。 有关更多信息,请参阅 非阻塞重试spring-doc.cadn.net.cn

B.2.3. 监听器容器变更

The onlyLogRecordMetadata 容器属性现在默认为 truespring-doc.cadn.net.cn

一个新的容器属性stopImmediate现在可用。spring-doc.cadn.net.cn

监听器容器属性 以获取更多信息。spring-doc.cadn.net.cn

使用一个BackOff在重试尝试之间的错误处理程序(例如:SeekToCurrentErrorHandlerDefaultAfterRollbackProcessor)现在会在容器停止后不久退出退避间隔,而不是延迟停止。spring-doc.cadn.net.cn

错误处理器和回滚后处理程序,如果它们扩展自FailedRecordProcessor,现在可以配置一个或多个RetryListener以接收关于重试和恢复进度的信息。spring-doc.cadn.net.cn

The RecordInterceptor 现在有在监听器返回(通常情况下或通过抛出异常)之后调用的额外方法。它还有一个子接口 ConsumerAwareRecordInterceptor。此外,现在为批量监听器提供了一个 BatchInterceptor。 请参见 消息监听容器 以获取更多信息。spring-doc.cadn.net.cn

B.2.4. @KafkaListener变更

您可以现在验证@KafkaHandler方法(类级别侦听器)的payload参数。 请参见@KafkaListener @Payload 验证以获取更多信息。spring-doc.cadn.net.cn

你可以在MessagingMessageConverterBatchMessagingMessageConverter上设置rawRecordHeader属性,这会导致原始的ConsumerRecord被添加到转换后的Message<?>中。 这种情况下非常有用,例如如果你想在一个监听器错误处理器中使用一个DeadLetterPublishingRecoverer。 有关更多信息,请参见监听器错误处理器spring-doc.cadn.net.cn

您现在可以在应用程序初始化期间修改@KafkaListener注解。 有关更多信息,请参阅@KafkaListener 属性修改spring-doc.cadn.net.cn

B.2.5. DeadLetterPublishingRecover变更

现在,如果键和值的反序列化都失败,则会将原始值发布到DLT。 此前,值会被填充但键DeserializationException仍然保留在头部。 存在打破API的更改,如果您继承了恢复器并重写了createProducerRecord方法。spring-doc.cadn.net.cn

此外,恢复器会在发布到目标解析器之前验证由目标解析器选择的分区是否确实存在。spring-doc.cadn.net.cn

发布死信记录以获得更多信息。spring-doc.cadn.net.cn

B.2.6. ChainedKafkaTransactionManageris Deprecated

See 交易 以获取更多信息。spring-doc.cadn.net.cn

B.2.7. ReplyingKafkaTemplate变更

现在有一个机制可以检查回复并在将来如果存在某些条件时异常失败。spring-doc.cadn.net.cn

已添加发送和接收spring-messagingMessage<?>的功能。spring-doc.cadn.net.cn

B.2.8. Kafka Streams 变更

默认情况下,StreamsBuilderFactoryBean 现在配置为不清理本地状态。 有关更多信息,请参阅 配置spring-doc.cadn.net.cn

B.2.9. KafkaAdmin变更

新方法 createOrModifyTopicsdescribeTopics 已被添加。 KafkaAdmin.NewTopics 被添加以便在单个 bean 中配置多个主题。 有关详细信息,请参阅 配置主题spring-doc.cadn.net.cn

B.2.10. MessageConverter变更

现在可以向spring-messagingSmartMessageConverter添加一个MessagingMessageConverter,允许根据contentType标头进行内容协商。 有关更多信息,请参阅Spring 消息消息转换spring-doc.cadn.net.cn

B.2.12. ExponentialBackOffWithMaxRetries

spring-doc.cadn.net.cn

A new BackOff implementation is provided, making it more convenient to configure the max retries.spring-doc.cadn.net.cn

See ExponentialBackOffWithMaxRetries Implementation for more information.spring-doc.cadn.net.cn

spring-doc.cadn.net.cn

B.2.13. 条件委托错误处理器

这些新的错误处理程序可以根据异常类型委托给不同的错误处理程序进行配置。 有关更多信息,请参阅委托的错误处理程序spring-doc.cadn.net.cn

B.3. 2.5 和 2.6 之间的变更

B.3.1. Kafka 客户端版本

此版本需要 2.6.0 kafka-clientsspring-doc.cadn.net.cn

B.3.2. 监听器容器变更

各种错误处理器(继承自FailedRecordProcessor)和DefaultAfterRollbackProcessor现在在恢复失败时会重置BackOff。此外,您现在可以根据失败记录和/或异常来选择要使用的BackOffspring-doc.cadn.net.cn

您现在可以在容器属性中配置一个adviceChain。 有关更多信息,请参阅监听器容器属性spring-doc.cadn.net.cn

当容器配置为发布ListenerContainerIdleEvent时,现在在发送记录后会发布一个ListenerContainerNoLongerIdleEvent,并且在此过程中会发出空闲事件。 有关更多信息,请参阅应用程序事件检测空闲和无响应的消费者spring-doc.cadn.net.cn

B.3.3. @KafkaListener 变更

当使用手动分区分配时,现在可以指定通配符以确定哪些分区应重置为初始偏移量。 此外,如果监听器实现ConsumerSeekAware,则在手动分配后调用onPartitionsAssigned()。 (此功能也在版本2.5.5中添加)。 有关更多信息,请参阅显式分区分配spring-doc.cadn.net.cn

方便的方法已添加到AbstractConsumerSeekAware以使定位更加容易。 有关更多信息,请参见特定偏移量定位spring-doc.cadn.net.cn

B.3.4. 错误处理程序更改

子类的FailedRecordProcessor(例如:SeekToCurrentErrorHandlerDefaultAfterRollbackProcessorRecoveringBatchErrorHandler)现在可以配置为如果异常类型与之前记录中的类型不同,则重置重试状态。spring-doc.cadn.net.cn

B.3.5. 生产者工厂变更

您可以现在为生产者设置一个最大年龄,在达到该年龄后,它们将会被关闭并重新创建。 请参见事务以获取更多信息。spring-doc.cadn.net.cn

您现在可以在DefaultKafkaProducerFactory创建之后更新配置映射。 这可能很有用,例如,在凭据更改后,您需要更新SSL密钥/信任存储的位置。 有关更多信息,请参阅使用DefaultKafkaProducerFactoryspring-doc.cadn.net.cn

B.4. 2.4 和 2.5 之间的变更

此部分涵盖了从版本2.4到版本2.5所做的更改。对于早期版本的变更历史,请参见变更历史spring-doc.cadn.net.cn

B.4.1. 消费者/生产者工厂变更

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.cadn.net.cn

你现在可以更改运行时的 Bootstrap 服务器属性,从而允许在另一个 Kafka 集群之间进行切换。更多详情请参见连接到 Kafkaspring-doc.cadn.net.cn

B.4.2. StreamsBuilderFactoryBean变更

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.cadn.net.cn

B.4.3. Kafka 客户端版本

这个版本需要 2.5.0 版本的 kafka-clientsspring-doc.cadn.net.cn

B.4.4. 类/包更改

SeekUtils 已从 o.s.k.support 包移动到 o.s.k.listenerspring-doc.cadn.net.cn

B.4.5. 传递尝试头

现在在使用某些错误处理器和回滚处理器时,可以添加一个跟踪投递尝试的头部选项。 更多信息,请参阅投递尝试头部spring-doc.cadn.net.cn

B.4.6. @KafkaListener 变更

Default reply headers 将会在需要时自动填充,如果返回类型为 @KafkaListener。 见 Reply Type Message<?> 以获取更多信息。spring-doc.cadn.net.cn

The 0 是不再填充为 1 值的,当传入记录包含 2 键时;头部完全省略了。spring-doc.cadn.net.cn

@KafkaListener 方法现在可以指定一个 ConsumerRecordMetadata 参数,而不是使用主题、分区等元数据的独立头部。 请参阅 消费者记录元数据 以获取更多信息。spring-doc.cadn.net.cn

B.4.7. 监听器容器变更

The assignmentCommitOption容器属性现在默认为LATEST_ONLY_NO_TX。 请参阅监听器容器属性以获取更多信息。spring-doc.cadn.net.cn

The subBatchPerPartition容器属性现在默认为true当使用事务时。 请参阅事务以获取更多信息。spring-doc.cadn.net.cn

一个全新的RecoveringBatchErrorHandler现在提供了。spring-doc.cadn.net.cn

静态组成员资格现在受到支持。 请参阅消息监听容器以获取更多信息。spring-doc.cadn.net.cn

当增量/协作重新平衡被配置时,如果偏移量因非致命错误RebalanceInProgressException而无法提交,在重新平衡完成后,容器将尝试为仍分配给此实例的分区重试提交偏移量。spring-doc.cadn.net.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.cadn.net.cn

您现在可以控制标准错误处理器故意抛出的异常的日志记录级别。 请参阅容器错误处理程序以获取更多信息。spring-doc.cadn.net.cn

The getAssignmentsByClientId()方法已添加,使在并发容器中确定分配给哪个分区的消费者变得更加容易。 有关更多信息,请参阅监听器容器属性spring-doc.cadn.net.cn

您现在可以抑制日志记录整个ConsumerRecords在错误、调试日志等中。请参见监听器容器属性中的#container-props部分。spring-doc.cadn.net.cn

B.4.8. KafkaTemplate 变更

The KafkaTemplate 现在可以维护 micrometer 计时器。 更多信息,请参阅 监控spring-doc.cadn.net.cn

The KafkaTemplate 现在可以配置 ProducerConfig 属性以覆盖生产者工厂中的属性。 参见 使用 KafkaTemplate 以获取更多信息。spring-doc.cadn.net.cn

一个 RoutingKafkaTemplate 现在已经被提供。 请参见 使用 RoutingKafkaTemplate 以获取更多信息。spring-doc.cadn.net.cn

您现在可以使用KafkaSendCallback代替ListenerFutureCallback来获取更窄的异常,从而更容易提取失败的ProducerRecord。更多信息请参阅使用KafkaTemplatespring-doc.cadn.net.cn

B.4.9. Kafka 字符串序列化器/反序列化器

ToStringSerializer/StringDeserializer个实体以及相关的SerDe现在提供。 请参见字符串序列化获取更多信息。spring-doc.cadn.net.cn

B.4.10. JsonDeserializer

The JsonDeserializer 现在更具灵活性来确定反序列化类型。 请参阅 通过方法确定类型 以获取更多详细信息。spring-doc.cadn.net.cn

B.4.11. 委托序列化器/反序列化器

The DelegatingSerializer 现在可以处理“标准”类型,当出站记录没有头部时。 更多信息,请参见 委托序列化器和反序列化器spring-doc.cadn.net.cn

B.4.12. 测试更改

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

B.5. 2.3 和 2.4 之间的变更

B.5.1. Kafka 客户端版本

此版本需要 2.4.0 kafka-clients 或更高版本,并支持新的增量重新平衡功能。spring-doc.cadn.net.cn

B.5.2. ConsumerAwareRebalanceListener

ConsumerRebalanceListener 这个接口现在有了一个新的方法 onPartitionsLost。 请参阅 Apache Kafka 文档以获取更多信息。spring-doc.cadn.net.cn

不同于ConsumerRebalanceListener,默认实现不会调用onPartitionsRevoked。相反,监听器容器会在调用完onPartitionsLost之后再调用该方法;因此,在实现ConsumerAwareRebalanceListener时不应做同样的事情。spring-doc.cadn.net.cn

重平衡侦听器的末尾,您可以看到更多相关信息,了解更多详情。spring-doc.cadn.net.cn

B.5.3. 通用错误处理器

The isAckAfterHandle() 默认实现现在默认返回true。spring-doc.cadn.net.cn

B.5.4. KafkaTemplate

The KafkaTemplate 现在支持非事务性发布与事务性发布的并行使用。 See KafkaTemplate 事务性和非事务性发布 以获取更多信息。spring-doc.cadn.net.cn

B.5.5. 聚合回复Kafka模板

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.cadn.net.cn

聚合多个回复 以获得更多信息。spring-doc.cadn.net.cn

B.5.6. 监听器容器

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.cadn.net.cn

B.5.7. @KafkaListener

The <code>0</code> annotation has a new property <code>1</code>; default true. When a replying listener returns an <code>2</code> this property controls whether the return result is sent as a single record or a record for each element is sent. See <a href=\"3\">Forwarding Listener Results using <code>4</code></a> for more informationspring-doc.cadn.net.cn

批处理监听器现在可以配置为BatchToRecordAdapter; 这使得,例如,批处理可以在事务中进行处理,而监听器每次只接收一条记录。 默认实现下,可以使用ConsumerRecordRecoverer来在批处理内部处理错误,而不停止整个批处理的处理 - 在使用事务时这可能很有用。 有关更多信息,请参阅使用批处理监听器的事务spring-doc.cadn.net.cn

B.5.8. Kafka Streams

The StreamsBuilderFactoryBean 接受一个新的属性 KafkaStreamsInfrastructureCustomizer。 这允许在创建流之前配置构建器和/或拓扑结构。 有关更多信息,请参阅 Spring 管理spring-doc.cadn.net.cn

B.6. 2.2 和 2.3 之间的变化

此部分涵盖了从版本 2.2 到版本 2.3 的更改。spring-doc.cadn.net.cn

B.6.1. 技巧、窍门和示例

一个新的章节 技巧、窍门和示例 已经添加。 请为该章节的其他条目提交 GitHub 问题或/和拉取请求。spring-doc.cadn.net.cn

B.6.2. Kafka 客户端版本

此版本需要2.3.0 kafka-clients 或更高版本。spring-doc.cadn.net.cn

B.6.3. 类/包更改

TopicPartitionInitialOffset 已被 TopicPartitionOffset 代替。spring-doc.cadn.net.cn

B.6.4. 配置更改

自2.3.4版本起,missingTopicsFatal容器属性默认为false。 当此设置为true时,如果代理器宕机,则应用程序将无法启动;许多用户都受到了这一更改的影响;鉴于Kafka是一个高可用性平台,我们并未预料到没有活动代理器的情况下启动应用程序会是一种常见的用例。spring-doc.cadn.net.cn

B.6.5. 生产者和消费者工厂变更

The DefaultKafkaProducerFactory 现在可以配置为每个线程创建一个生产者。 您还可以通过构造函数提供 Supplier<Serializer> 实例作为另一种选择,而不是使用配置的类(这些类需要无参构造函数),或者使用 Serializer 实例进行构造,这些实例将在所有生产者之间共享。 请参阅 使用 DefaultKafkaProducerFactory 以获取更多详细信息。spring-doc.cadn.net.cn

spring-doc.cadn.net.cn

Supplier<Deserializer>个实例的DefaultKafkaConsumerFactory中也提供了相同的选项。spring-doc.cadn.net.cn

更多关于使用KafkaMessageListenerContainer的信息。spring-doc.cadn.net.cn

spring-doc.cadn.net.cn

B.6.6. 监听器容器变更

此前,当使用监听器适配器(例如2s)调用监听器时,错误处理程序接收到的参数为ListenerExecutionFailedException(实际监听器异常作为cause)。spring-doc.cadn.net.cn

spring-doc.cadn.net.cn

由原生GenericMessageListener抛出的异常未修改地传递给错误处理程序。spring-doc.cadn.net.cn

现在,错误处理程序始终接收一个ListenerExecutionFailedException参数(实际监听器异常作为cause),这提供了访问容器的group.id属性的能力。spring-doc.cadn.net.cn

spring-doc.cadn.net.cn

因为监听容器有自己的提交偏移量的机制,它更偏好于Kafka ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG被设置为false。 现在,除非在消费者工厂或容器的消费者属性中明确设置,否则它会自动设置为false。spring-doc.cadn.net.cn

The ackOnError 属性现在默认为 falsespring-doc.cadn.net.cn

现在可以在侦听器方法中获取消费者对象的group.id属性。 有关更多信息,请参见获取消费者group.id属性spring-doc.cadn.net.cn

spring-doc.cadn.net.cn

容器有一个新的属性recordInterceptor,允许在调用监听器之前检查或修改记录。spring-doc.cadn.net.cn

还提供了CompositeRecordInterceptor,以防您需要调用多个拦截器。spring-doc.cadn.net.cn

有关更多信息,请参见消息监听容器spring-doc.cadn.net.cn

spring-doc.cadn.net.cn

spring-doc.cadn.net.cn

对于从开始,结束或当前位置进行相对寻求以及寻求第一个大于或等于时间戳的偏移量,ConsumerSeekAware现在具有新的方法。有关更多信息,请参见定位到特定偏移量spring-doc.cadn.net.cn

spring-doc.cadn.net.cn

spring-doc.cadn.net.cn

现在提供了一个方便的类 AbstractConsumerSeekAware,用于简化寻求操作。spring-doc.cadn.net.cn

有关更多信息,请参见 寻求到特定偏移量spring-doc.cadn.net.cn

spring-doc.cadn.net.cn

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

spring-doc.cadn.net.cn

当使用AckMode.MANUAL(或MANUAL_IMMEDIATE)时,您现在可以通过在Acknowledgment上调用nack来触发重投递。更多信息请参见提交偏移量spring-doc.cadn.net.cn

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

现在,容器发布与启动相关的额外消费者生命周期事件。 有关更多信息,请参见应用程序事件spring-doc.cadn.net.cn

事务性批处理监听器现在可以支持僵尸围栏。 详情请见事务spring-doc.cadn.net.cn

监听器容器工厂现在可以配置为ContainerCustomizer,以便在创建和配置容器后进一步配置每个容器。 有关更多信息,请参见容器工厂spring-doc.cadn.net.cn

B.6.7. 错误处理程序更改

The SeekToCurrentErrorHandler 现在将某些异常视为致命的,并在首次失败时禁用重试,调用恢复器。spring-doc.cadn.net.cn

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

从版本 2.3.2 开始,当错误处理程序在恢复失败记录后返回时,已恢复记录的偏移量将被提交。spring-doc.cadn.net.cn

spring-doc.cadn.net.cn

DeadLetterPublishingRecovererErrorHandlingDeserializer结合使用时,现在将发送到死信主题的消息的负载设置为无法反序列化的原始值。spring-doc.cadn.net.cn

以前是null,用户代码需要从消息标头中提取DeserializationExceptionspring-doc.cadn.net.cn

有关更多信息,请参见发布死信记录spring-doc.cadn.net.cn

spring-doc.cadn.net.cn

B.6.8. 主题构建器

spring-doc.cadn.net.cn

A new class TopicBuilder is provided for more convenient creation of NewTopic @Bean s for automatic topic provisioning.spring-doc.cadn.net.cn

See Configuring Topics for more information.spring-doc.cadn.net.cn

spring-doc.cadn.net.cn

B.6.9. Kafka Streams 变更

您现在可以对通过@EnableKafkaStreams创建的StreamsBuilderFactoryBean执行额外的配置。 有关更多信息,请参见流配置spring-doc.cadn.net.cn

spring-doc.cadn.net.cn

A RecoveringDeserializationExceptionHandler is now provided which allows records with deserialization errors to be recovered.spring-doc.cadn.net.cn

It can be used in conjunction with a DeadLetterPublishingRecoverer to send these records to a dead-letter topic.spring-doc.cadn.net.cn

See Recovery from Deserialization Exceptions for more information.spring-doc.cadn.net.cn

spring-doc.cadn.net.cn

使用SpEL生成头信息,已经提供了HeaderEnricher转换器。有关更多信息,请参见Header Enricherspring-doc.cadn.net.cn

spring-doc.cadn.net.cn

已提供 MessagingTransformerspring-doc.cadn.net.cn

这允许 Kafka 流拓扑与 SpringMessaging 组件(如 Spring Integration 流)进行交互。spring-doc.cadn.net.cn

有关更多信息,请参见 MessagingTransformerKStream 调用 Spring Integration 流spring-doc.cadn.net.cn

spring-doc.cadn.net.cn

B.6.10. JSON 组件更改

spring-doc.cadn.net.cn

现在,所有支持JSON的功能组件默认由由ObjectMapper生成的Jackson JacksonUtils.enhancedObjectMapper()进行配置。spring-doc.cadn.net.cn

JsonDeserializer现在提供了基于TypeReference的构造函数,以更好地处理目标泛型容器类型。spring-doc.cadn.net.cn

此外,引入了一个新的JacksonMimeTypeModule用于序列化org.springframework.util.MimeType为简单的字符串。spring-doc.cadn.net.cn

有关更多信息,请参阅其JavaDoc和序列化、反序列化和消息转换spring-doc.cadn.net.cn

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

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

spring-doc.cadn.net.cn

B.6.11. ReplyingKafkaTemplate

当回复超时,future将以0而不是1完成异常。spring-doc.cadn.net.cn

也提供了带有消息级别的回复超时指定的重载sendAndReceive方法。spring-doc.cadn.net.cn

B.6.12. 聚合回复Kafka模板

spring-doc.cadn.net.cn

通过聚合来自多个接收者的回复,扩展了ReplyingKafkaTemplatespring-doc.cadn.net.cn

有关更多信息,请参见聚合多个回复spring-doc.cadn.net.cn

spring-doc.cadn.net.cn

B.6.13. 事务变更

您现在可以在transactionIdPrefix上覆写生产者工厂的KafkaTemplateKafkaTransactionManager。 有关更多信息,请参阅transactionIdPrefixspring-doc.cadn.net.cn

B.6.14. 新的委托序列化器/反序列化器

spring-doc.cadn.net.cn

框架现在提供了一个委托的 SerializerDeserializer,利用一个头部来启用生成和消费具有多种键值类型的记录。spring-doc.cadn.net.cn

有关更多信息,请参见 委托序列化器和反序列化器spring-doc.cadn.net.cn

spring-doc.cadn.net.cn

B.6.15. 新的重试反序列化器

spring-doc.cadn.net.cn

框架现在提供了一个委托的 RetryingDeserializer,用于在可能由于网络问题等临时错误而重试序列化的情况下的重试序列化器。有关更多信息,请参见 重试反序列器spring-doc.cadn.net.cn

spring-doc.cadn.net.cn

B.7. 2.1 和 2.2 之间的变化

B.7.1. Kafka 客户端版本

此版本需要 2.0.0 kafka-clients 或更高版本。spring-doc.cadn.net.cn

B.7.2. 类和包的变更

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

The AckMode 枚举已被从 AbstractMessageListenerContainer 移动到 ContainerPropertiesspring-doc.cadn.net.cn

The setBatchErrorHandler()setErrorHandler() 方法已被从 ContainerProperties 移动到 AbstractMessageListenerContainerAbstractKafkaListenerContainerFactoryspring-doc.cadn.net.cn

B.7.3. 回滚处理后

spring-doc.cadn.net.cn

A new AfterRollbackProcessor strategy is provided.spring-doc.cadn.net.cn

See After-rollback Processor for more information.spring-doc.cadn.net.cn

spring-doc.cadn.net.cn

B.7.4. ConcurrentKafkaListenerContainerFactory变更

您现在可以使用 ConcurrentKafkaListenerContainerFactory 创建和配置任何 ConcurrentMessageListenerContainer,而不仅仅是 @KafkaListener 注解的那些。 有关更多信息,请参阅有关 容器工厂 的说明。spring-doc.cadn.net.cn

B.7.5. 监听器容器的变更

spring-doc.cadn.net.cn

已添加一个新的容器属性(missingTopicsFatal)。spring-doc.cadn.net.cn

有关更多信息,请参见使用KafkaMessageListenerContainerspring-doc.cadn.net.cn

spring-doc.cadn.net.cn

当消费者停止时,现在会发出一个0。 详细信息请参见有关线程安全的更多信息。spring-doc.cadn.net.cn

批处理侦听器可以选择接收完整的ConsumerRecords<?, ?>对象,而不是List<ConsumerRecord<?, ?>对象。 有关更多信息,请参见批处理侦听器spring-doc.cadn.net.cn

The DefaultAfterRollbackProcessorSeekToCurrentErrorHandler 现在可以恢复(跳过)持续失败的记录,并且默认情况下会在 10 次失败后进行此操作。它们可以配置为将失败的记录发布到死信主题。spring-doc.cadn.net.cn

使用版本2.2.4后,可以在选择死信主题名称时使用消费者的组ID。spring-doc.cadn.net.cn

spring-doc.cadn.net.cn

数字 ConsumerStoppingEvent 已经被添加。spring-doc.cadn.net.cn

有关更多信息,请参见 应用事件spring-doc.cadn.net.cn

spring-doc.cadn.net.cn

The SeekToCurrentErrorHandler 现在可以配置为在容器使用 AckMode.MANUAL_IMMEDIATE 配置时提交恢复记录的偏移量(自 2.2.4 版起).spring-doc.cadn.net.cn

B.7.6. @KafkaListener 变更

现在,您可以通过在注解上设置属性来覆盖侦听器容器工厂的concurrencyautoStartup属性。 现在,您可以添加配置以确定是否复制哪些标头到回复消息中。 有关更多信息,请参见@KafkaListener注解spring-doc.cadn.net.cn

现在,您可以在自己的注解上使用@KafkaListener作为元注解。有关更多信息,请参见@KafkaListener作为元注解spring-doc.cadn.net.cn

spring-doc.cadn.net.cn

现在更容易为Validator配置@Payload验证。spring-doc.cadn.net.cn

有关更多信息,请参见@KafkaListener @Payload验证spring-doc.cadn.net.cn

spring-doc.cadn.net.cn

您现在可以直接在注解上指定kafka消费者属性;这些属性将覆盖消费者工厂中具有相同名称的任何属性(自2.2.4版以来)。 有关更多信息,请参见注解属性spring-doc.cadn.net.cn

B.7.7. 标头映射更改

Headers of type MimeTypeMediaType 现在映射为简单的字符串类型,在RecordHeader值中。 之前,它们被映射为 JSON,并且只有MimeType会被解码。MediaType无法被解码。 现在为了互操作性,它们是简单的字符串。spring-doc.cadn.net.cn

同时,DefaultKafkaHeaderMapper有一个新的addToStringClasses方法,允许指定应该使用toString()而不是JSON来映射的类型。更多信息请参见消息标头spring-doc.cadn.net.cn

B.7.8. 嵌入式 Kafka 变更

spring-doc.cadn.net.cn

The KafkaEmbedded class and its KafkaRule interface have been deprecated in favor of the EmbeddedKafkaBroker and its JUnit 4 EmbeddedKafkaRule wrapper.spring-doc.cadn.net.cn

The @EmbeddedKafka annotation now populates an EmbeddedKafkaBroker bean instead of the deprecated KafkaEmbedded.spring-doc.cadn.net.cn

This change allows the use of @EmbeddedKafka in JUnit 5 tests.spring-doc.cadn.net.cn

The @EmbeddedKafka annotation now has the attribute ports to specify the port that populates the EmbeddedKafkaBroker.spring-doc.cadn.net.cn

See Testing Applications for more information.spring-doc.cadn.net.cn

spring-doc.cadn.net.cn

B.7.9. JsonSerializer/Deserializer 增强功能

您可以现在通过使用生产者和消费者属性来提供类型映射信息。spring-doc.cadn.net.cn

新的反序列化构造函数可供使用,允许通过提供的目标类型覆盖类型头部信息。spring-doc.cadn.net.cn

The JsonDeserializer 现在默认移除任何类型信息头部。spring-doc.cadn.net.cn

您现在可以通过使用一个Kafka属性来配置JsonDeserializer以忽略类型信息头(从2.2.3版本开始)。spring-doc.cadn.net.cn

B.7.10. Kafka Streams 变更

Spring框架中,流配置bean现在必须是一个KafkaStreamsConfiguration对象,而不是一个StreamsConfig对象。spring-doc.cadn.net.cn

StreamsBuilderFactoryBean已被从包…​core移动到…​configspring-doc.cadn.net.cn

spring-doc.cadn.net.cn

当基于KStream实例构建条件分支时,为了提高最终用户体验,已经引入了KafkaStreamBrancherspring-doc.cadn.net.cn

spring-doc.cadn.net.cn

B.7.11. 事务性 ID

当监听容器启动事务时,transactional.id 现在是 transactionIdPrefix 附加上 <group.id>.<topic>.<partition>。 这个变化允许正确隔离僵尸对象,如这里所述spring-doc.cadn.net.cn

B.8. 2.0 和 2.1 之间的变更

B.8.1. Kafka 客户端版本

此版本需要1.0.0 kafka-clients 或更高版本。spring-doc.cadn.net.cn

1.1.x 版本客户端在 2.2 版本中得到了原生支持。spring-doc.cadn.net.cn

B.8.2. JSON 改进

spring-doc.cadn.net.cn

现在,在Headers中添加了类型信息,StringJsonMessageConverterJsonSerializer,使得转换器和JsonDeserializer可以根据消息本身而不是固定配置的类型,在接收时创建特定的类型。spring-doc.cadn.net.cn

有关更多信息,请参阅序列化、反序列化和消息转换spring-doc.cadn.net.cn

spring-doc.cadn.net.cn

B.8.3. 容器停止错误处理器

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.cadn.net.cn

B.8.4. 暂停和恢复容器

spring-doc.cadn.net.cn

监听容器现在具有 pause()resume() 种方法(自版本 2.1.3 起)。spring-doc.cadn.net.cn

有关更多信息,请参见 暂停和恢复监听容器spring-doc.cadn.net.cn

spring-doc.cadn.net.cn

B.8.5. 有状态重试

从版本2.1.3开始,您可以配置状态化重试。 更多信息,请参见状态化重试spring-doc.cadn.net.cn

B.8.6. 客户端 ID

从 2.1.1 版本开始,你现在可以在 @KafkaListener 前面设置 client.id 前缀。 此前,要自定义客户端 ID,你需要为每个监听器分别配置一个消费者工厂(和容器工厂)。 前缀会在使用并发时自动后接 -n 以提供唯一的客户端 ID。spring-doc.cadn.net.cn

B.8.7. 日志记录偏移提交

默认情况下,主题偏移提交的日志记录使用 DEBUG 日志级别执行。 从版本 2.1.2 开始,在名为 ContainerProperties 的新属性中,您可以指定这些消息的日志级别。 有关更多信息,请参阅 使用 KafkaMessageListenerContainerspring-doc.cadn.net.cn

B.8.8. 默认 @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.cadn.net.cn

B.8.9. ReplyingKafkaTemplate

从版本2.1.3开始,提供了一个KafkaTemplate的子类来支持请求/回复语义。 有关更多信息,请参见使用ReplyingKafkaTemplatespring-doc.cadn.net.cn

B.8.10. 串联Kafka事务管理器

Version 2.1.3 引入了 ChainedKafkaTransactionManager。 (现在已弃用)spring-doc.cadn.net.cn

B.8.11. 从2.0迁移指南

B.9. 1.3 和 2.0 之间的变更

B.9.1. Spring框架和Java版本

The Spring for Apache Kafka项目现在需要Spring框架5.0和Java 8。spring-doc.cadn.net.cn

B.9.2. @KafkaListener变更

现在,您可以注解@KafkaListener个方法(和类以及@KafkaHandler个方法)使用@SendTo。 如果该方法返回结果,则将其转发到指定主题。 有关更多信息,请参阅使用@SendTo转发侦听器结果spring-doc.cadn.net.cn

B.9.3. 消息监听器

消息监听器现在可以了解Consumer对象。 见消息监听器获取更多信息。spring-doc.cadn.net.cn

B.9.4. 使用 ConsumerAwareRebalanceListener

重平衡侦听器现在可以在重平衡通知期间访问Consumer对象。有关更多信息,请参见重平衡侦听器spring-doc.cadn.net.cn

B.10. 1.2 和 1.3 之间的变更

B.10.1. 对事务的支持

0.11.0.0 客户端库增加了对事务的支持。 KafkaTransactionManager 和其他对事务的支持已经添加。 有关更多信息,请参阅 事务spring-doc.cadn.net.cn

B.10.2. 对 Headers 的支持

0.11.0.0 客户端库增加了对消息头的支持。 这些现在可以映射到和从 spring-messaging MessageHeaders。 有关更多信息,请参见 消息头spring-doc.cadn.net.cn

B.10.3. 创建主题

0.11.0.0 客户端库提供了一个 AdminClient,你可以使用它来创建主题。 KafkaAdmin 使用此客户端自动添加定义为 @Bean 实例的主题。spring-doc.cadn.net.cn

B.10.4. 对 Kafka 时间戳的支持

KafkaTemplate 现在支持带有时间戳的记录添加API。 新引入了关于KafkaHeaderstimestamp支持。 此外,还新增了KafkaConditions.timestamp()KafkaMatchers.hasTimestamp()测试实用程序。 有关更多详细信息,请参阅使用KafkaTemplate@KafkaListener注解测试应用程序spring-doc.cadn.net.cn

B.10.5. @KafkaListener变更

spring-doc.cadn.net.cn

现在,您可以配置一个KafkaListenerErrorHandler来处理异常。spring-doc.cadn.net.cn

有关更多信息,请参见处理异常spring-doc.cadn.net.cn

spring-doc.cadn.net.cn

默认情况下,现在使用@KafkaListenerid属性作为group.id属性,覆盖在消费者工厂中配置的相应属性(如果存在的话)。 此外,您还可以显式地在注解上配置groupId。 以前,如果您需要使用不同的group.id值为监听器设置不同的容器工厂和消费者工厂。 为了恢复之前的使用在工厂中配置的group.id的行为,请将注解上的idIsGroup属性设置为falsespring-doc.cadn.net.cn

B.10.6. @EmbeddedKafka注解

spring-doc.cadn.net.cn

为了方便起见,提供了一个测试类级别的@EmbeddedKafka注解,用于注册KafkaEmbedded作为bean。spring-doc.cadn.net.cn

有关更多信息,请参见测试应用程序spring-doc.cadn.net.cn

spring-doc.cadn.net.cn

B.10.7. Kerberos 配置

支持现在提供了通过Kerberos进行配置的功能。 有关更多详细信息,请参见JAAS和Kerberosspring-doc.cadn.net.cn

B.11. 1.1 和 1.2 之间的变更

此版本使用的是0.10.2.x客户端。spring-doc.cadn.net.cn

B.12. 1.0 和 1.1 之间的变更

B.12.1. Kafka 客户端

此版本使用了 Apache Kafka 0.10.x.x 客户端。spring-doc.cadn.net.cn

B.12.2. 批量监听器

Listeners可以配置为接收由consumer.poll()操作返回的整个消息批次,而不是逐个接收。spring-doc.cadn.net.cn

B.12.3. 空负载

null payload 被用于在使用日志压缩时“删除”键。spring-doc.cadn.net.cn

B.12.4. 初始偏移量

当显式分配分区时,现在可以配置消费者组的初始偏移量相对于当前位置,而不仅仅是绝对位置或相对于当前末尾的位置。spring-doc.cadn.net.cn

B.12.5. 查找

您现在可以寻求每个主题或分区的位置。 当使用群组管理并且Kafka分配分区时,您可以将其用于初始化期间设置初始位置。 您也可以在检测到空闲容器或应用程序执行的任何任意点进行寻求。 有关更多信息,请参阅有关寻求特定偏移量的更多信息。spring-doc.cadn.net.cn