You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@storm.apache.org by ka...@apache.org on 2016/06/24 09:02:57 UTC
[1/3] storm git commit: STORM-1914 : Storm Kafka Field Topic Selector
Repository: storm
Updated Branches:
refs/heads/master 83b1f059a -> 9773f0538
STORM-1914 : Storm Kafka Field Topic Selector
Project: http://git-wip-us.apache.org/repos/asf/storm/repo
Commit: http://git-wip-us.apache.org/repos/asf/storm/commit/3d53861c
Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/3d53861c
Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/3d53861c
Branch: refs/heads/master
Commit: 3d53861cd0e58b38804803aab837fea62bef899f
Parents: 8ea9e5b
Author: darionyaphet <da...@gmail.com>
Authored: Sat Jun 18 14:36:58 2016 +0800
Committer: darionyaphet <da...@gmail.com>
Committed: Wed Jun 22 15:25:07 2016 +0800
----------------------------------------------------------------------
external/storm-kafka/README.md | 4 ++
.../bolt/selector/FieldIndexTopicSelector.java | 48 +++++++++++++++++++
.../bolt/selector/FieldNameTopicSelector.java | 49 ++++++++++++++++++++
3 files changed, 101 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/storm/blob/3d53861c/external/storm-kafka/README.md
----------------------------------------------------------------------
diff --git a/external/storm-kafka/README.md b/external/storm-kafka/README.md
index 7db8675..0a07629 100644
--- a/external/storm-kafka/README.md
+++ b/external/storm-kafka/README.md
@@ -275,6 +275,10 @@ public interface KafkaTopicSelector {
The implementation of this interface should return the topic to which the tuple's key/message mapping needs to be published
You can return a null and the message will be ignored. If you have one static topic name then you can use
DefaultTopicSelector.java and set the name of the topic in the constructor.
+`FieldNameTopicSelector` and `FieldIndexTopicSelector` use to support decided which topic should to push message from tuple.
+User could specify the field name or field index in tuple ,selector will use this value as topic name which to publish message.
+When the topic name not found , `KafkaBolt` will write messages into default topic .
+Please make sure the default topic have created .
### Specifying Kafka producer properties
You can provide all the produce properties in your Storm topology by calling `KafkaBolt.withProducerProperties()` and `TridentKafkaStateFactory.withProducerProperties()`. Please see http://kafka.apache.org/documentation.html#newproducerconfigs
http://git-wip-us.apache.org/repos/asf/storm/blob/3d53861c/external/storm-kafka/src/jvm/org/apache/storm/kafka/bolt/selector/FieldIndexTopicSelector.java
----------------------------------------------------------------------
diff --git a/external/storm-kafka/src/jvm/org/apache/storm/kafka/bolt/selector/FieldIndexTopicSelector.java b/external/storm-kafka/src/jvm/org/apache/storm/kafka/bolt/selector/FieldIndexTopicSelector.java
new file mode 100644
index 0000000..7b52403
--- /dev/null
+++ b/external/storm-kafka/src/jvm/org/apache/storm/kafka/bolt/selector/FieldIndexTopicSelector.java
@@ -0,0 +1,48 @@
+/**
+ * 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.storm.kafka.bolt.selector;
+
+import org.apache.storm.tuple.Tuple;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Uses field index to select topic name from tuple .
+ */
+public class FieldIndexTopicSelector implements KafkaTopicSelector {
+
+ private static final Logger LOG = LoggerFactory.getLogger(FieldIndexTopicSelector.class);
+
+ private final int fieldIndex;
+ private final String defaultTopicName;
+
+ public FieldIndexTopicSelector(int fieldIndex, String defaultTopicName) {
+ this.fieldIndex = fieldIndex;
+ this.defaultTopicName = defaultTopicName;
+ }
+
+ @Override
+ public String getTopic(Tuple tuple) {
+ if (fieldIndex < tuple.size()) {
+ return tuple.getString(fieldIndex);
+ } else {
+ LOG.warn("Field Index " + fieldIndex + " Out of bound . Using default topic " + defaultTopicName);
+ return defaultTopicName;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/storm/blob/3d53861c/external/storm-kafka/src/jvm/org/apache/storm/kafka/bolt/selector/FieldNameTopicSelector.java
----------------------------------------------------------------------
diff --git a/external/storm-kafka/src/jvm/org/apache/storm/kafka/bolt/selector/FieldNameTopicSelector.java b/external/storm-kafka/src/jvm/org/apache/storm/kafka/bolt/selector/FieldNameTopicSelector.java
new file mode 100644
index 0000000..a622e8f
--- /dev/null
+++ b/external/storm-kafka/src/jvm/org/apache/storm/kafka/bolt/selector/FieldNameTopicSelector.java
@@ -0,0 +1,49 @@
+/**
+ * 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.storm.kafka.bolt.selector;
+
+import org.apache.storm.tuple.Tuple;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Uses field name to select topic name from tuple .
+ */
+public class FieldNameTopicSelector implements KafkaTopicSelector {
+
+ private static final Logger LOG = LoggerFactory.getLogger(FieldNameTopicSelector.class);
+
+ private final String fieldName;
+ private final String defaultTopicName;
+
+
+ public FieldNameTopicSelector(String fieldName, String defaultTopicName) {
+ this.fieldName = fieldName;
+ this.defaultTopicName = defaultTopicName;
+ }
+
+ @Override
+ public String getTopic(Tuple tuple) {
+ if (tuple.contains(fieldName)) {
+ return tuple.getStringByField(fieldName);
+ } else {
+ LOG.warn("Field " + fieldName + " Not Found . Using default topic " + defaultTopicName);
+ return defaultTopicName;
+ }
+ }
+}
[2/3] storm git commit: Merge branch 'STORM-1914' of
https://github.com/darionyaphet/storm into STORM-1914
Posted by ka...@apache.org.
Merge branch 'STORM-1914' of https://github.com/darionyaphet/storm into STORM-1914
Project: http://git-wip-us.apache.org/repos/asf/storm/repo
Commit: http://git-wip-us.apache.org/repos/asf/storm/commit/a7d69fbe
Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/a7d69fbe
Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/a7d69fbe
Branch: refs/heads/master
Commit: a7d69fbe3e759a0a5a7487ebf531e484fd955b84
Parents: 83b1f05 3d53861
Author: Jungtaek Lim <ka...@gmail.com>
Authored: Fri Jun 24 18:00:49 2016 +0900
Committer: Jungtaek Lim <ka...@gmail.com>
Committed: Fri Jun 24 18:00:49 2016 +0900
----------------------------------------------------------------------
external/storm-kafka/README.md | 4 ++
.../bolt/selector/FieldIndexTopicSelector.java | 48 +++++++++++++++++++
.../bolt/selector/FieldNameTopicSelector.java | 49 ++++++++++++++++++++
3 files changed, 101 insertions(+)
----------------------------------------------------------------------
[3/3] storm git commit: add STORM-1914 to CHANGELOG
Posted by ka...@apache.org.
add STORM-1914 to CHANGELOG
Project: http://git-wip-us.apache.org/repos/asf/storm/repo
Commit: http://git-wip-us.apache.org/repos/asf/storm/commit/9773f053
Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/9773f053
Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/9773f053
Branch: refs/heads/master
Commit: 9773f05387e5c23f762eeb0aeb0255e9f854167f
Parents: a7d69fb
Author: Jungtaek Lim <ka...@gmail.com>
Authored: Fri Jun 24 18:01:32 2016 +0900
Committer: Jungtaek Lim <ka...@gmail.com>
Committed: Fri Jun 24 18:01:32 2016 +0900
----------------------------------------------------------------------
CHANGELOG.md | 1 +
1 file changed, 1 insertion(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/storm/blob/9773f053/CHANGELOG.md
----------------------------------------------------------------------
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4eb0080..15b417c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -108,6 +108,7 @@
* STORM-1769: Added a test to check local nimbus with notifier plugin
## 1.1.0
+ * STORM-1914: Storm Kafka Field Topic Selector
* STORM-1925: Remove Nimbus thrift call from Nimbus itself
* STORM-1907: PartitionedTridentSpoutExecutor has incompatible types that cause ClassCastException
* STORM-1136: Command line module to return kafka spout offsets lag and display in storm ui.