首页 > 其他 > 详细

SparkStreaming结合Kafka使用

时间:2014-09-10 17:29:50      阅读:239      评论:0      收藏:0      [点我收藏+]

spark自带的example中就有streaming结合kafka使用的案例:

$SPARK_HOME/examples/src/main/scala/org/apache/spark/examples/streaming/KafkaWordCount.scala

使用方法参见代码描述:

Usage: KafkaWordCount <zkQuorum> <group> <topics> <numThreads>
<zkQuorum> is a list of one or more zookeeper servers that make quorum
<group> is the name of kafka consumer group
<topics> is a list of one or more kafka topics to consume from
<numThreads> is the number of threads the kafka consumer should use

Example:
`$ bin/run-example org.apache.spark.examples.streaming.KafkaWordCount zoo01,zoo02,zoo03 my-consumer-group topic1,topic2 1`

 运行步骤:

1、启动ZK

zkServer.sh start

2、启动KAFKA SERVER

kafka-server-start.sh  $KAFKA_HOME/config/server.properties &  

3、运行Producer

run-example org.apache.spark.examples.streaming.KafkaWordCountProducer hadoop000:9092 test 3 5

参数描述:

  hadoop000:9092表示producer的地址和端口;

  test表示topic;

  3表示每秒发多少条消息;

  5表示每条消息中有几个单词;

4、运行Consumer

run-example org.apache.spark.examples.streaming.KafkaWordCount hadoop000:2181 test-consumer-group test 1

参数描述:

  hadoop000:2181表示zookeeper的监听地址;

  test-consumer-group表示consumer-group的名称,必须和$KAFKA_HOME/config/consumer.properties中的group.id的配置内容一致;

  test表示topic;

  1表示线程数;

注意观察consumer控制台的数据输出

 


参考许鹏博客

SparkStreaming结合Kafka使用

原文:http://www.cnblogs.com/luogankun/p/3964650.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!