Interface DeserializationFailureHandler<T>
- Type Parameters:
T- the expected type
public interface DeserializationFailureHandler<T>
Bean invoked on Kafka deserialization to implement custom failure handling.
Implementors must use @Identifier to provide a name to the bean.
This name is then referenced in the channel configuration:
mp.messaging.incoming.my-channel.[key|value]-deserialization-failure-handler=name.
In case a Kafka Record's key or value cannot be deserialized, this bean can provide failure handling via Mutiny's
Uni interface to retry or to provide a fallback value.
null is an accepted fallback value.
If this bean throws an exception, this is considered as a fatal failure and the application is reported unhealthy.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringHeader name for deserialization failure cause if any.static final StringHeader name passing the data that was not able to be deserialized.static final StringHeader name passing the class name of the underlying deserializer.static final StringHeader name used when the deserialization failure happened on a key.static final StringHeader name for deserialization failure message.static final StringHeader name for the topic of the incoming message when a deserialization failure happen.static final byte[] -
Method Summary
Modifier and TypeMethodDescriptionstatic org.apache.kafka.common.header.HeadersaddFailureDetailsToHeaders(String deserializer, String topic, boolean isKey, org.apache.kafka.common.header.Headers headers, byte[] data, Throwable failure) Extend record headers to add deserialization failure reason to the incoming message headersdefault TdecorateDeserialization(io.smallrye.mutiny.Uni<T> deserialization, String topic, boolean isKey, String deserializer, byte[] data, org.apache.kafka.common.header.Headers headers) Decorate the given wrapped deserialization action to apply fault tolerance actions.default ThandleDeserializationFailure(String topic, boolean isKey, String deserializer, byte[] data, Exception exception, org.apache.kafka.common.header.Headers headers) Handles a deserialization issue for a record's key or value.
-
Field Details
-
DESERIALIZATION_FAILURE_REASON
Header name for deserialization failure message.- See Also:
-
DESERIALIZATION_FAILURE_CAUSE
Header name for deserialization failure cause if any.- See Also:
-
DESERIALIZATION_FAILURE_IS_KEY
Header name used when the deserialization failure happened on a key. The value is"true"in this case, absent otherwise.- See Also:
-
DESERIALIZATION_FAILURE_TOPIC
Header name for the topic of the incoming message when a deserialization failure happen.- See Also:
-
DESERIALIZATION_FAILURE_DATA
Header name passing the data that was not able to be deserialized.- See Also:
-
DESERIALIZATION_FAILURE_DESERIALIZER
Header name passing the class name of the underlying deserializer.- See Also:
-
TRUE_VALUE
static final byte[] TRUE_VALUE
-
-
Method Details
-
handleDeserializationFailure
default T handleDeserializationFailure(String topic, boolean isKey, String deserializer, byte[] data, Exception exception, org.apache.kafka.common.header.Headers headers) Handles a deserialization issue for a record's key or value.- Parameters:
topic- the topicisKey- whether the failure happened when deserializing a record's key.deserializer- the used deserializerdata- the data that was not deserialized correctlyexception- the exceptionheaders- the record headers, extended with the failure reason, causes, and data. May also benull- Returns:
- the fallback
T
-
decorateDeserialization
default T decorateDeserialization(io.smallrye.mutiny.Uni<T> deserialization, String topic, boolean isKey, String deserializer, byte[] data, org.apache.kafka.common.header.Headers headers) Decorate the given wrapped deserialization action to apply fault tolerance actions. The default implementation callshandleDeserializationFailure(java.lang.String, boolean, java.lang.String, byte[], java.lang.Exception, org.apache.kafka.common.header.Headers)for retro compatibility.- Parameters:
deserialization- the deserialization call wrapped inUnitopic- the topicisKey- whether the deserialization is for a record's key.deserializer- the used deserializerdata- the data to deserializeheaders- the record headers. May benull- Returns:
- the recovered
T
-
addFailureDetailsToHeaders
static org.apache.kafka.common.header.Headers addFailureDetailsToHeaders(String deserializer, String topic, boolean isKey, org.apache.kafka.common.header.Headers headers, byte[] data, Throwable failure) Extend record headers to add deserialization failure reason to the incoming message headers- Parameters:
deserializer- deserializer class nametopic- the topicisKey- whether the failure happened when deserializing a record's key.headers- the record headersdata- the data that was not deserialized correctlyfailure- the deserilization failure- Returns:
- headers
-