【问题标题】:spark streaming kafka issue while streaming is started开始流式传输时引发流式传输 kafka 问题
【发布时间】:2019-05-19 13:41:31
【问题描述】:

我正在尝试使用 spark2-shell 从 kafka 消费者那里读取数据。

请在下面找到我的代码。

我以以下方式启动我的 spark2-shell:

spark2-shell --jars kafka-clients-0.10.1.2.6.2.0-205.jar, spark-sql-kafka-0-10_2.11-2.1.1.jar 

请找到我的以下代码:

import org.apache.kafka.clients.consumer.ConsumerRecord
import org.apache.kafka.common.serialization.StringDeserializer
import org.apache.spark.streaming._
import org.apache.spark.streaming.dstream.InputDStream
import org.apache.spark.streaming.kafka010.{ConsumerStrategies, KafkaUtils, LocationStrategies}
import spark.implicits._

val ssc = new StreamingContext(sc, Seconds(2))

val topics = List("testingtopic01")

val preferredHosts = LocationStrategies.PreferConsistent

val kafkaParams = Map(
    "bootstrap.servers" -> "localhost:9192",
    "key.deserializer" -> classOf[StringDeserializer],
    "value.deserializer" -> classOf[StringDeserializer],
    "security.protocol" -> "SASL_PLAINTEXT",
    "auto.offset.reset" -> "earliest",
    "group.id" -> "spark-streaming-consumer-group"
  )

  
  
val lines = KafkaUtils.createDirectStream[String, String](
      ssc,
      preferredHosts,
      ConsumerStrategies.Subscribe[String, String](topics.distinct, kafkaParams)
    )
	
lines.print()

ssc.start()

但是在我开始使用 spark-streaming 之后,这里什么都没有显示。

scala> ssc.start() 
18/12/19 15:50:07 WARN streaming.StreamingContext:DynamicAllocation is enabled for this application.Enabling Dynamic allocation for Spark Streaming applications can cause data loss if Write Ahead Log is not enabled for non-replayable sources like Flume. See the programming guide for details on how to enable the Write Ahead Log.

请建议我绕过此问题的方法。

提前致谢。

【问题讨论】:

    标签: scala apache-spark spark-streaming-kafka


    【解决方案1】:

    您应该设置 spark.streaming.dynamicAllocation.enable=false。 有关更多说明,您可以访问 Dynamic Allocation for Spark Streaming

    【讨论】:

      猜你喜欢
      • 2016-03-24
      • 2018-03-28
      • 2016-04-27
      • 2018-07-09
      • 1970-01-01
      • 2020-12-02
      • 2015-12-12
      • 2018-02-13
      • 2018-11-18
      相关资源
      最近更新 更多