java.lang.ClassCastException: kafka.cluster.BrokerEndPoint cannot be cast to kafka.cluster.Broker

使用SparkStreaming 读取kafka数据进行处理,程序启动报异常:

java.lang.ClassCastException: kafka.cluster.BrokerEndPoint cannot be cast to kafka.cluster.Broker

原因是kafka client版本和  spark-streaming-kafka 版本不匹配造成的。

pom文件改成如下:

 spark-project
    ruleEngine
    pom
    1.0-SNAPSHOT

    
        UTF-8
        1.8
        1.8
    
    
        
            junit
            junit
            4.11
            test
        
        
            org.apache.spark
            spark-core_2.11
            2.2.0
            
                
                    zookeeper
                    org.apache.zookeeper
                
            
        

        
            org.apache.spark
            spark-streaming_2.11
            2.2.0

        
        
            org.apache.spark
            spark-sql_2.11
            2.2.0
            
                
                    spark-core_2.11
                    org.apache.spark
                
                
                    spark-tags_2.11
                    org.apache.spark
                
                
                    spark-unsafe_2.11
                    org.apache.spark
                
            
        
        
            com.alibaba
            fastjson
            1.1.41
        

        
            org.apache.spark
            spark-streaming-kafka-0-8_2.11
            2.2.0
            
                
                    kafka_2.11
                    org.apache.kafka
                
                
                    spark-tags_2.11
                    org.apache.spark
                
            
        
        
            org.apache.kafka
            kafka_2.11
            0.8.2.1
            
                
                    log4j
                    log4j
                
            
        
        
            org.apache.httpcomponents
            httpclient
            4.5.6
        
        
            org.apache.kafka
            kafka-clients
            0.10.0.0
        
        
            mysql
            mysql-connector-java
            5.1.6
        

        
            com.alibaba
            druid
            1.1.10
        

    

其中这两处的依赖版本要匹配:

       
            org.apache.spark
            spark-streaming-kafka-0-8_2.11
            2.2.0
       

       
            org.apache.kafka
            kafka_2.11
            0.8.2.1
       

你可能感兴趣的:(java.lang.ClassCastException: kafka.cluster.BrokerEndPoint cannot be cast to kafka.cluster.Broker)