如何使用ErrorHandlingDeserializer2处理反序列化过程中的异常
How to use ErrorHandlingDeserializer2 to handle exceptions during deserialization
我正在使用 spring-kafka - 2.2.7.RELEASE 并试图了解如何配置 ErrorHandlingDeserializer2 以在反序列化期间处理异常并 logs/send 它们 DLT。我正在按照以下文档设置我的消费者配置
https://docs.spring.io/spring-kafka/docs/2.2.0.RELEASE/reference/html/_reference.html#error-handling-deserializer.
这里我的问题是,我们如何抓取异常和反序列化失败的消费者记录?
考虑将 Apache Kafka 2.3.1
升级到 Spring。
这是一份如何满足您的要求的文档:https://docs.spring.io/spring-kafka/docs/2.3.0.RELEASE/reference/html/#dead-letters
Starting with version 2.3, when used in conjunction with an ErrorHandlingDeserializer2
, the publisher (read as DeadLetterPublishingRecoverer
) will restore the record value()
, in the dead-letter producer record, to the original value that failed to be deserialized. Previously, the value()
was null and user code had to decode the DeserializationException
from the message headers. In addition, you can provide multiple KafkaTemplate
s to the publisher; this might be needed, for example, if you want to publish the byte[]
from a DeserializationException
, as well as values using a different serializer from records that were deserialized successfully. Here is an example of configuring the publisher with KafkaTemplate
s that use a String and byte[] serializer:
因此,我相信该文档甚至为您提供了如何在 2.2.x
.
版本中进行操作的线索
顺便说一句,我们始终建议至少升级到这一代的最新版本。目前那个是2.2.10
:https://spring.io/projects/spring-kafka#learn
我正在使用 spring-kafka - 2.2.7.RELEASE 并试图了解如何配置 ErrorHandlingDeserializer2 以在反序列化期间处理异常并 logs/send 它们 DLT。我正在按照以下文档设置我的消费者配置 https://docs.spring.io/spring-kafka/docs/2.2.0.RELEASE/reference/html/_reference.html#error-handling-deserializer.
这里我的问题是,我们如何抓取异常和反序列化失败的消费者记录?
考虑将 Apache Kafka 2.3.1
升级到 Spring。
这是一份如何满足您的要求的文档:https://docs.spring.io/spring-kafka/docs/2.3.0.RELEASE/reference/html/#dead-letters
Starting with version 2.3, when used in conjunction with an
ErrorHandlingDeserializer2
, the publisher (read asDeadLetterPublishingRecoverer
) will restore the recordvalue()
, in the dead-letter producer record, to the original value that failed to be deserialized. Previously, thevalue()
was null and user code had to decode theDeserializationException
from the message headers. In addition, you can provide multipleKafkaTemplate
s to the publisher; this might be needed, for example, if you want to publish thebyte[]
from aDeserializationException
, as well as values using a different serializer from records that were deserialized successfully. Here is an example of configuring the publisher withKafkaTemplate
s that use a String and byte[] serializer:
因此,我相信该文档甚至为您提供了如何在 2.2.x
.
顺便说一句,我们始终建议至少升级到这一代的最新版本。目前那个是2.2.10
:https://spring.io/projects/spring-kafka#learn