All Downloads are FREE. Search and download functionalities are using the official Maven repository.

kafka.entity.changelog.serde.CreationEventSerde Maven / Gradle / Ivy

package kafka.entity.changelog.serde;

import com.google.protobuf.InvalidProtocolBufferException;
import kafka.entity.changelog.schema.Topic;
import org.apache.kafka.common.serialization.Deserializer;
import org.apache.kafka.common.serialization.Serde;
import org.apache.kafka.common.serialization.Serializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CreationEventSerde implements Serde {

  static final Logger LOG = LoggerFactory.getLogger(CreationEventSerde.class);

  @Override public Serializer serializer() {
    return (topic, data) -> {
      if (data != null) return data.toByteArray();
      else return new byte[]{};
    };
  }

  @Override public Deserializer deserializer() {
    return (topic, data) -> {
      try {
        return Topic.CreationEvent.parseFrom(data);
      } catch (InvalidProtocolBufferException e) {
        LOG.error("Error deserializing topic event", e);
        return null;
      }
    };
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy