-
Notifications
You must be signed in to change notification settings - Fork 28.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPARK-4964][Streaming][Kafka] More updates to Exactly-once Kafka stream #4384
Closed
Closed
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6a91cab
Added example
tdas 4986784
Added unit test to kafka offset recovery
tdas e73589c
Minor changes.
tdas 50f2b56
Added Java API and added more Scala and Java unit tests. Also updated…
tdas bb65232
Fixed test bug and refactored KafkaStreamSuite
tdas e4abf69
Scala doc improvements and stuff.
tdas 26df23c
Updates based on PR comments from Cody
tdas 83d0402
Added JavaDirectKafkaWordCount example.
tdas 3ed9284
updated scala doc
tdas 7c931c3
Small update
tdas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
.../scala-2.10/src/main/scala/org/apache/spark/examples/streaming/DirectKafkaWordCount.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.spark.examples.streaming | ||
|
||
import kafka.serializer.StringDecoder | ||
|
||
import org.apache.spark.streaming._ | ||
import org.apache.spark.streaming.kafka._ | ||
import org.apache.spark.SparkConf | ||
|
||
/** | ||
* Consumes messages from one or more topics in Kafka and does wordcount. | ||
* Usage: DirectKafkaWordCount <brokers> <topics> | ||
* <brokers> is a list of one or more Kafka brokers | ||
* <topics> is a list of one or more kafka topics to consume from | ||
* | ||
* Example: | ||
* $ bin/run-example streaming.KafkaWordCount broker1-host:port,broker2-host:port topic1,topic2 | ||
*/ | ||
object DirectKafkaWordCount { | ||
def main(args: Array[String]) { | ||
if (args.length < 2) { | ||
System.err.println("Usage: DirectKafkaWordCount <broker list> <topic>") | ||
System.exit(1) | ||
} | ||
|
||
StreamingExamples.setStreamingLogLevels() | ||
|
||
val Array(brokerList, topics) = args | ||
val sparkConf = new SparkConf().setAppName("DirectKafkaWordCount") | ||
val ssc = new StreamingContext(sparkConf, Seconds(2)) | ||
ssc.checkpoint("checkpoint") | ||
|
||
val topicsSet = topics.split(",").toSet | ||
val kafkaParams = Map[String, String]("metadata.broker.list" -> brokerList) | ||
val lines = KafkaUtils.createDirectStream[String, String, StringDecoder, StringDecoder]( | ||
ssc, kafkaParams, topicsSet).map(_._2) | ||
val words = lines.flatMap(_.split(" ")) | ||
val wordCounts = words.map(x => (x, 1L)).reduceByKey(_ + _) | ||
wordCounts.print() | ||
|
||
ssc.start() | ||
ssc.awaitTermination() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You removed the "not zookeeper servers" note here, but left it in for the other methods that take kafkaParams
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only reason we were writing "not zookeepers" is to make the difference with the earlier stream clear, for people who want to switch from the old one or the new. That applies to the public API. This is internal private API. I can add it back, no issues.