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
@Identifierto 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
Uniinterface to retry or to provide a fallback value.nullis 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
Fields Modifier and Type Field Description static StringDESERIALIZATION_FAILURE_CAUSEHeader name for deserialization failure cause if any.static StringDESERIALIZATION_FAILURE_DATAHeader name passing the data that was not able to be deserialized.static StringDESERIALIZATION_FAILURE_DESERIALIZERHeader name passing the class name of the underlying deserializer.static StringDESERIALIZATION_FAILURE_IS_KEYHeader name used when the deserialization failure happened on a key.static StringDESERIALIZATION_FAILURE_REASONHeader name for deserialization failure message.static StringDESERIALIZATION_FAILURE_TOPICHeader name for the topic of the incoming message when a deserialization failure happen.static byte[]TRUE_VALUE
-
Method Summary
All Methods Static Methods Instance Methods Default Methods Modifier and Type Method Description static 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 Detail
-
DESERIALIZATION_FAILURE_REASON
static final String DESERIALIZATION_FAILURE_REASON
Header name for deserialization failure message.- See Also:
- Constant Field Values
-
DESERIALIZATION_FAILURE_CAUSE
static final String DESERIALIZATION_FAILURE_CAUSE
Header name for deserialization failure cause if any.- See Also:
- Constant Field Values
-
DESERIALIZATION_FAILURE_IS_KEY
static final String 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:
- Constant Field Values
-
DESERIALIZATION_FAILURE_TOPIC
static final String DESERIALIZATION_FAILURE_TOPIC
Header name for the topic of the incoming message when a deserialization failure happen.- See Also:
- Constant Field Values
-
DESERIALIZATION_FAILURE_DATA
static final String DESERIALIZATION_FAILURE_DATA
Header name passing the data that was not able to be deserialized.- See Also:
- Constant Field Values
-
DESERIALIZATION_FAILURE_DESERIALIZER
static final String DESERIALIZATION_FAILURE_DESERIALIZER
Header name passing the class name of the underlying deserializer.- See Also:
- Constant Field Values
-
TRUE_VALUE
static final byte[] TRUE_VALUE
-
-
Method Detail
-
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
-
-