You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2019/07/20 00:58:27 UTC

[GitHub] [incubator-druid] abossert commented on a change in pull request #8112: removed hard-coded Kafka key and value deserializer

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_r305561008
 
 

 ##########
 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"));
 
 Review comment:
   I ended up with an error doing it this way, so I did this instead: ByteArrayDeserializer.class.getTypeName()

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org