Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala Apache Spark,从单个卡夫卡输入主题到两个输出卡夫卡主题_Scala_Apache Spark_Apache Kafka - Fatal编程技术网

Scala Apache Spark,从单个卡夫卡输入主题到两个输出卡夫卡主题

Scala Apache Spark,从单个卡夫卡输入主题到两个输出卡夫卡主题,scala,apache-spark,apache-kafka,Scala,Apache Spark,Apache Kafka,一般来说,我需要的工作流程是: 接收来自卡夫卡主题的消息raw 将字符串解析为case类 将所有错误发送到卡夫卡主题error reduceByKey解析的消息 将结果发送到Kafka topicparsed 卡夫卡主题的提交偏移量raw 后藤(1) 输入数据:Input:String 输出: 我尝试了两种方法来完成我的工作流程: 使用Spark RDD-不起作用,因为在reduceByKey之后,我无法获取提交RDD.asInstanceOf[HasOffsetRanges].offsetRa

一般来说,我需要的工作流程是:

  • 接收来自卡夫卡主题的消息
    raw
  • 将字符串解析为case类
  • 将所有错误发送到卡夫卡主题
    error
  • reduceByKey
    解析的消息
  • 将结果发送到Kafka topic
    parsed
  • 卡夫卡主题的提交偏移量
    raw
    后藤(1)
  • 输入数据:
    Input:String
    输出:

    我尝试了两种方法来完成我的工作流程:

  • 使用Spark RDD-不起作用,因为在
    reduceByKey
    之后,我无法获取提交
    RDD.asInstanceOf[HasOffsetRanges].offsetRanges的卡夫卡偏移范围,因为在第一次
    RDD.map{…}
    之后它丢失了
  • 我尝试使用结构化流媒体(因为它必须管理偏移):
  • 但是有编译问题

    found   : org.apache.spark.sql.Dataset[Product with Serializable with Message]
     required: org.apache.spark.sql.Dataset[Message]
    Note: Product with Serializable with Message <: Message, but class Dataset is invariant in type T.
    
    found:org.apache.spark.sql.Dataset[带有可序列化消息的产品]
    必需:org.apache.spark.sql.Dataset[消息]
    注意:带有可序列化消息的产品
    
    .flatMap {
        case raw: RawMessage =>
            implicit val mapperInfo: ProviderKey = ProviderKey(RawMessageParser.name, RawMessageParser.version, 0)
    
            Try(parse[List[ParsedMessage]](Left(raw.nxMessage))) match {
                case Success(msg) =>
                    msg
                case Failure(ex) =>
                    Seq(ParseError(raw.nxMessage, ex))
            }
    }
    
    found   : org.apache.spark.sql.Dataset[Product with Serializable with Message]
     required: org.apache.spark.sql.Dataset[Message]
    Note: Product with Serializable with Message <: Message, but class Dataset is invariant in type T.