转载自 KafkaUtils.createDirectStream()参数详解 - 海贼王一样的男人 - 博客园
通过KafkaUtils.createDirectStream该方法创建kafka的DStream数据源,传入有三个参数:ssc,LocationStrategies,ConsumerStrategies。
LocationStrategies有三种策略:PreferBrokers,PreferConsistent,PreferFixed详情查看上边源码解析
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
/** * :: Experimental :: object to obtain instances of [[LocationStrategy]] * */ @ Experimental object LocationStrategies {
/** * :: Experimental :: * Use this only if your executors are on the same nodes as your Kafka brokers. 只有当executors数量等于brokers数量时使用 */ @ Experimental def PreferBrokers : LocationStrategy = org.apache.spark.streaming.kafka 010 .PreferBrokers /** * :: Experimental :: * Use this in most cases, it will consistently distribute partitions across all executors.大多数使用,在所有的executors分配分区 */ @ Experimental def PreferConsistent : LocationStrategy = org.apache.spark.streaming.kafka 010 .PreferConsistent |