Search in sources :

Example 1 with CanCommitOffsets

use of org.apache.spark.streaming.kafka010.CanCommitOffsets in project lambda-arch by apssouza22.

the class TrafficOffsetCommitCallback method commitOffset.

/**
 * Commit the ack to kafka after process have completed
 *
 * @param directKafkaStream
 */
private void commitOffset(JavaInputDStream<ConsumerRecord<String, IoTData>> directKafkaStream) {
    directKafkaStream.foreachRDD((JavaRDD<ConsumerRecord<String, IoTData>> trafficRdd) -> {
        if (!trafficRdd.isEmpty()) {
            OffsetRange[] offsetRanges = ((HasOffsetRanges) trafficRdd.rdd()).offsetRanges();
            CanCommitOffsets canCommitOffsets = (CanCommitOffsets) directKafkaStream.inputDStream();
            canCommitOffsets.commitAsync(offsetRanges, new TrafficOffsetCommitCallback());
        }
    });
}
Also used : OffsetRange(org.apache.spark.streaming.kafka010.OffsetRange) CanCommitOffsets(org.apache.spark.streaming.kafka010.CanCommitOffsets) IoTData(com.apssouza.iot.dto.IoTData) HasOffsetRanges(org.apache.spark.streaming.kafka010.HasOffsetRanges) JavaRDD(org.apache.spark.api.java.JavaRDD)

Example 2 with CanCommitOffsets

use of org.apache.spark.streaming.kafka010.CanCommitOffsets in project lambda-arch by apssouza22.

the class TrafficOffsetCommitCallback method commitOffset.

/**
 * Commit the ack to kafka after process have completed
 * This is our fault-tolerance implementation
 *
 * @param directKafkaStream
 */
private void commitOffset(JavaInputDStream<ConsumerRecord<String, IoTData>> directKafkaStream) {
    directKafkaStream.foreachRDD((JavaRDD<ConsumerRecord<String, IoTData>> trafficRdd) -> {
        if (!trafficRdd.isEmpty()) {
            OffsetRange[] offsetRanges = ((HasOffsetRanges) trafficRdd.rdd()).offsetRanges();
            CanCommitOffsets canCommitOffsets = (CanCommitOffsets) directKafkaStream.inputDStream();
            canCommitOffsets.commitAsync(offsetRanges, new TrafficOffsetCommitCallback());
        }
    });
}
Also used : OffsetRange(org.apache.spark.streaming.kafka010.OffsetRange) CanCommitOffsets(org.apache.spark.streaming.kafka010.CanCommitOffsets) IoTData(com.apssouza.iot.common.dto.IoTData) HasOffsetRanges(org.apache.spark.streaming.kafka010.HasOffsetRanges) JavaRDD(org.apache.spark.api.java.JavaRDD)

Aggregations

JavaRDD (org.apache.spark.api.java.JavaRDD)2 CanCommitOffsets (org.apache.spark.streaming.kafka010.CanCommitOffsets)2 HasOffsetRanges (org.apache.spark.streaming.kafka010.HasOffsetRanges)2 OffsetRange (org.apache.spark.streaming.kafka010.OffsetRange)2 IoTData (com.apssouza.iot.common.dto.IoTData)1 IoTData (com.apssouza.iot.dto.IoTData)1