问题
How to specify consumer group id for kafka spark streaming using direct stream API.
HashMap<String, String> kafkaParams = new HashMap<String, String>();
kafkaParams.put("metadata.broker.list", brokers);
kafkaParams.put("auto.offset.reset", "largest");
kafkaParams.put("group.id", "app1");
JavaPairInputDStream<String, String> messages = KafkaUtils.createDirectStream(
jssc,
String.class,
String.class,
StringDecoder.class,
StringDecoder.class,
kafkaParams,
topicsSet
);
though i have specified the configuration not sure if missing something. using spark1.3
kafkaParams.put("group.id", "app1");
回答1:
The direct stream API use the low level Kafka API, and as so doesn't use consumer groups in anyway. If you want to use consumer groups with Spark Streaming, you'll have to use the receiver based API.
Full details are available in the doc !
回答2:
createDirectStream
in spark-streaming-kafka-0-8
does not support group mode, because it's using the low-level Kafka API.
But spark-streaming-kafka-0-10
supports group mode.
Consumer Configs
In 0.9.0.0 we introduced the new Java consumer as a replacement for the older Scala-based simple and high-level consumers. The configs for both new and old consumers are described below.
In the New Consumer Configs
, it has the group.id
item.
The Spark Streaming integration for Kafka 0.10
is using the new API. https://spark.apache.org/docs/2.1.1/streaming-kafka-0-10-integration.html
The Spark Streaming integration for Kafka 0.10 is similar in design to the 0.8 Direct Stream approach. It provides simple parallelism, 1:1 correspondence between Kafka partitions and Spark partitions, and access to offsets and metadata. However, because the newer integration uses the new Kafka consumer API instead of the simple API, there are notable differences in usage.
I've tested the group mode in spark-streaming-kafka-0-10
, it does work.
来源:https://stackoverflow.com/questions/36508553/how-to-specify-consumer-group-in-kafka-spark-streaming-using-direct-stream