abossert commented on a change in pull request #8112: removed hard-coded Kafka 
key and value deserializer
URL: https://github.com/apache/incubator-druid/pull/8112#discussion_r305561052
 
 

 ##########
 File path: 
extensions-core/kafka-indexing-service/src/main/java/org/apache/druid/indexing/kafka/KafkaRecordSupplier.java
 ##########
 @@ -207,7 +210,40 @@ public static void addConsumerPropertiesFromConfig(
     ClassLoader currCtxCl = Thread.currentThread().getContextClassLoader();
     try {
       
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
-      return new KafkaConsumer<>(props, new ByteArrayDeserializer(), new 
ByteArrayDeserializer());
+      Deserializer keyDeserializerObject;
+      Deserializer valueDeserializerObject;
+  
+      try {
+        Class keyDeserializerClass = 
Class.forName(props.getProperty("key.deserializer", 
"org.apache.kafka.common.serialization.ByteArrayDeserializer"));
+        Method keyDeserializerMethod = 
keyDeserializerClass.getMethod("deserialize", String.class, byte[].class);
+        Type keyDeserializerReturnType = 
keyDeserializerMethod.getGenericReturnType();
+    
+        if (keyDeserializerReturnType.getTypeName().equals("byte[]")) {
+          keyDeserializerObject = (Deserializer) 
keyDeserializerClass.getConstructor().newInstance();
+        } else {
+          throw new IllegalArgumentException("Key deserializer must return a 
byte array (byte[]), " + keyDeserializerClass.getName() + " returns " + 
keyDeserializerReturnType.getTypeName());
+        }
+      }
+      catch (ClassNotFoundException | NoSuchMethodException | 
InstantiationException | IllegalAccessException | InvocationTargetException e) {
+        throw new StreamException(e);
+      }
+  
+      try {
+        Class valueDeserializerClass = 
Class.forName(props.getProperty("value.deserializer", 
"org.apache.kafka.common.serialization.ByteArrayDeserializer"));
+        Method valueDeserializerMethod = 
valueDeserializerClass.getMethod("deserialize", String.class, byte[].class);
+        Type valueDeserializerReturnType = 
valueDeserializerMethod.getGenericReturnType();
+    
+        if (valueDeserializerReturnType.getTypeName().equals("byte[]")) {
+          valueDeserializerObject = (Deserializer) 
valueDeserializerClass.getConstructor().newInstance();
+        } else {
+          throw new IllegalArgumentException("Key deserializer must return a 
byte array (byte[]), " + valueDeserializerClass.getName() + " returns " + 
valueDeserializerReturnType.getTypeName());
 
 Review comment:
   caught red-handed with a copy and paste error.  Fixed.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to