Interface SerializationFailureHandler<T>

  • Type Parameters:
    T - the expected type

    public interface SerializationFailureHandler<T>
    Bean invoked on Kafka serialization failure.

    Implementors must use @Identifier to provide a name to the bean. This name is then referenced in the channel configuration: mp.messaging.outgoing.my-channel.[key|value]-serialization-failure-handler=name.

    When a Kafka Record's key or value cannot be serialized, this bean is called to provide failure handling, such as retry or 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.

    • Method Summary

      All Methods Instance Methods Default Methods 
      Modifier and Type Method Description
      default byte[] decorateSerialization​(io.smallrye.mutiny.Uni<byte[]> serialization, String topic, boolean isKey, String serializer, T data, org.apache.kafka.common.header.Headers headers)
      Decorate the given wrapped serialization action to apply fault tolerance actions.
      default byte[] handleSerializationFailure​(String topic, boolean isKey, String serializer, T data, Exception exception, org.apache.kafka.common.header.Headers headers)
      Handles a serialization issue for a record's key or value.
    • Method Detail

      • handleSerializationFailure

        default byte[] handleSerializationFailure​(String topic,
                                                  boolean isKey,
                                                  String serializer,
                                                  T data,
                                                  Exception exception,
                                                  org.apache.kafka.common.header.Headers headers)
        Handles a serialization issue for a record's key or value.
        Parameters:
        topic - the topic
        isKey - whether the failure happened when deserializing a record's key.
        serializer - the used deserializer
        data - the data that was not deserialized correctly
        exception - the exception
        headers - the record headers, extended with the failure reason, causes, and data. May also be null
        Returns:
        the fallback T
      • decorateSerialization

        default byte[] decorateSerialization​(io.smallrye.mutiny.Uni<byte[]> serialization,
                                             String topic,
                                             boolean isKey,
                                             String serializer,
                                             T data,
                                             org.apache.kafka.common.header.Headers headers)
        Decorate the given wrapped serialization action to apply fault tolerance actions. The default implementation calls handleSerializationFailure(java.lang.String, boolean, java.lang.String, T, java.lang.Exception, org.apache.kafka.common.header.Headers) for retro compatibility.
        Parameters:
        serialization - the serialization call wrapped in Uni
        topic - the topic
        isKey - whether the deserialization is for a record's key.
        serializer - the used serializer
        data - the data to serialize
        headers - the record headers. May be null
        Returns:
        the recovered serialization result byte array