我有以下代码: -
val conf = new SparkConf()
.setMaster("local[3]")
.setAppName("KafkaReceiver")
.set("spark.cassandra.connection.host", "192.168.0.78")
.set("spark.cassandra.connection.keep_alive_ms", "20000")
.set("spark.executor.memory", "2g")
.set("spark.driver.memory", "4g")
.set("spark.submit.deployMode", "cluster")
.set("spark.cores.max", "10")
val sc = SparkContext.getOrCreate(conf)
val ssc = new StreamingContext(sc, Seconds(10))
val kafkaParams = Map[String, String](
"bootstrap.servers" -> "192.168.0.1:9092",
"group.id" -> "test-group-aditya")
val topics = Set("random")
val kafkaStream = KafkaUtils.createDirectStream[String, String, StringDecoder, StringDecoder](ssc, kafkaParams, topics)
在这段代码中我每隔10秒就从kafka流式传输数据,但是我正在寻找一些条件,我可以根据时间或流大小以MB /字节为单位流式传输,就像我设置5 MB一样因此,如果限制达到5 MB,我应该能够获取数据而不是等待10秒。请提出一些解决方案。谢谢,