use of org.apache.kafka.common.serialization.Deserializer in project druid by druid-io.
the class KafkaRecordSupplier method getKafkaDeserializer.
private static Deserializer getKafkaDeserializer(Properties properties, String kafkaConfigKey) {
Deserializer deserializerObject;
try {
Class deserializerClass = Class.forName(properties.getProperty(kafkaConfigKey, ByteArrayDeserializer.class.getTypeName()));
Method deserializerMethod = deserializerClass.getMethod("deserialize", String.class, byte[].class);
Type deserializerReturnType = deserializerMethod.getGenericReturnType();
if (deserializerReturnType == byte[].class) {
deserializerObject = (Deserializer) deserializerClass.getConstructor().newInstance();
} else {
throw new IllegalArgumentException("Kafka deserializers must return a byte array (byte[]), " + deserializerClass.getName() + " returns " + deserializerReturnType.getTypeName());
}
} catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
throw new StreamException(e);
}
return deserializerObject;
}
use of org.apache.kafka.common.serialization.Deserializer in project ksql by confluentinc.
the class RecordFormatter method newProtobufDeserializer.
private static Deserializer<?> newProtobufDeserializer(final SchemaRegistryClient srClient) {
final Printer printer = TextFormat.printer();
final KafkaProtobufDeserializer<?> inner = new KafkaProtobufDeserializer<>(srClient);
return (topic, data) -> {
final Message msg = inner.deserialize(topic, data);
if (msg == null) {
return null;
}
return printer.shortDebugString(msg);
};
}
use of org.apache.kafka.common.serialization.Deserializer in project ksql by confluentinc.
the class RecordFormatter method newStringDeserializer.
private static Deserializer<?> newStringDeserializer() {
final StringDeserializer deserializer = new StringDeserializer();
final String replacement = UTF_8.newDecoder().replacement();
return (Deserializer<Object>) (topic, data) -> {
if (data.length == 0) {
throw new DeserializationException("Empty data");
}
final String text = deserializer.deserialize("", data);
if (text.contains(replacement)) {
throw new DeserializationException("String contains replacement char");
}
return text;
};
}
Aggregations