sparkkafka在spark2.3.0中使用python流媒体

oxf4rvwz  于 2021-06-07  发布在  Kafka
关注(0)|答案(1)|浏览(327)

我最近升级到spark 2.3.0。我有一个现有的spark作业,它以前运行在spark2.2.0上。我正面临abstractmethoderror的java异常
我的简单代码:

from pyspark import SparkContext                                                                                  
from pyspark.streaming import StreamingContext                                                                    
from pyspark.streaming.kafka import KafkaUtils                                                                                                                                                                                       

 if __name__ == "__main__":                                                                                        
     print "Here it is!"                                                                                               
     sc = SparkContext(appName="Tester")                                                                           
     ssc = StreamingContext(sc, 1)

这在spark 2.2.0中运行良好
对于spark 2.3.0,我得到以下例外:

ssc = StreamingContext(sc, 1) 
  File "/usr/hdp/current/spark2-client/python/lib/pyspark.zip/pyspark/streaming/context.py", line 61, in __init__
  File "/usr/hdp/current/spark2-client/python/lib/pyspark.zip/pyspark/streaming/context.py", line 65, in _initialize_context
  File "/usr/hdp/current/spark2-client/python/lib/py4j-0.10.6-src.zip/py4j/java_gateway.py", line 1428, in __call__
  File "/usr/hdp/current/spark2-client/python/lib/py4j-0.10.6-src.zip/py4j/protocol.py", line 320, in get_return_value
py4j.protocol.Py4JJavaError: An error occurred while calling None.org.apache.spark.streaming.api.java.JavaStreamingContext.
: java.lang.AbstractMethodError
    at org.apache.spark.util.ListenerBus$class.$init$(ListenerBus.scala:35)
    at org.apache.spark.streaming.scheduler.StreamingListenerBus.<init>(StreamingListenerBus.scala:30)
    at org.apache.spark.streaming.scheduler.JobScheduler.<init>(JobScheduler.scala:57)
    at org.apache.spark.streaming.StreamingContext.<init>(StreamingContext.scala:184)
    at org.apache.spark.streaming.StreamingContext.<init>(StreamingContext.scala:76)
    at org.apache.spark.streaming.api.java.JavaStreamingContext.<init>(JavaStreamingContext.scala:130)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:247)
    at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
    at py4j.Gateway.invoke(Gateway.java:238)
    at py4j.commands.ConstructorCommand.invokeConstructor(ConstructorCommand.java:80)
    at py4j.commands.ConstructorCommand.execute(ConstructorCommand.java:69)
    at py4j.GatewayConnection.run(GatewayConnection.java:214)
    at java.lang.Thread.run(Thread.java:745)

我正在使用 spark-streaming-kafka-0-8_2.11-2.3.0.jar 对于带有-packages选项的spark submit命令。我试过用 spark-streaming-kafka-0-8-assembly_2.11-2.3.0.jar 以及--package和--jars选项。

Python version: 2.7.5

我跟随导游来到这里:https://spark.apache.org/docs/2.3.0/streaming-kafka-0-8-integration.html
spark streaming kafka版本0-8在2.3.0中已被弃用,但根据文档,它仍然存在。
我的命令如下:

spark-submit --master spark://10.183.0.41:7077 --packages org.apache.spark:spark-streaming-kafka-0-8_2.11:2.3.0  Kafka_test.py

当然,spark的scala底层代码发生了一些变化。
有人面临过同样的问题吗?

avkwfej4

avkwfej41#

https://spark.apache.org/docs/2.3.0/streaming-kafka-integration.html
spark2.3.0不支持kafka 0.8

相关问题