0
votes

I am trying to use below API for Spark streaming with Kafka. I have to stream avro serialized data with spark, the data is located in Kafka.

static <K,V,KD extends kafka.serializer.Decoder<K>,VD extends kafka.serializer.Decoder<V>,R> 
    JavaInputDStream<R> createDirectStream(JavaStreamingContext jssc, Class<K> keyClass, Class<V> valueClass, Class<KD> keyDecoderClass, Class<VD> valueDecoderClass, Class<R> recordClass, java.util.Map<String,String> kafkaParams, java.util.Map<kafka.common.TopicAndPartition,Long> fromOffsets, Function<kafka.message.MessageAndMetadata<K,V>,R> messageHandler)
    :: Experimental :: Create an input stream that directly pulls messages from Kafka Brokers without using any receiver.

Can i know What do i need to supply for parameter Class recordClass in the API? I have used the API like below,but it's giving compilation error.

All i want is to receive bytestream data into spark streaming from kafka.

JavaInputDStream<byte[]> directKafkaStream = KafkaUtils.createDirectStream(jsc, String.class, byte[].class,
        StringDecoder.class, DefaultDecoder.class, byte[].class, kafkaParams, topicMap,
        (Function<MessageAndMetadata<String, String>, String>) MessageAndMetadata::message);

Exception in thread "main" java.lang.Error: Unresolved compilation problems: The method createDirectStream(JavaStreamingContext, Class, Class, Class, Class, Class, Map, Map, Function,R>) in the type KafkaUtils is not applicable for the arguments (JavaStreamingContext, Class, Class, Class, Class, Class, Map, Map, Function,String>)

1

1 Answers

4
votes

Try this.

 JavaInputDStream<byte[]> directKafkaStream = KafkaUtils.createDirectStream(jssc, String.class, byte[].class,
                StringDecoder.class, DefaultDecoder.class, byte[].class, kafkaParams, fromOffset,
                (Function<MessageAndMetadata<String, byte[]>, byte[]>) MessageAndMetadata::message);

Here is an article for Kafka, Avro and Spark.