Github user hmcl commented on a diff in the pull request: https://github.com/apache/storm/pull/1687#discussion_r85981903 --- Diff: examples/storm-starter/src/jvm/org/apache/storm/starter/trident/TridentKafkaClientWordCountNamedTopics.java --- @@ -0,0 +1,122 @@ +/* + * 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.starter.trident; + +import org.apache.kafka.clients.consumer.ConsumerRecord; +import org.apache.storm.kafka.spout.KafkaSpoutConfig; +import org.apache.storm.kafka.spout.KafkaSpoutRetryExponentialBackoff; +import org.apache.storm.kafka.spout.KafkaSpoutRetryService; +import org.apache.storm.kafka.spout.KafkaSpoutStreams; +import org.apache.storm.kafka.spout.KafkaSpoutStreamsNamedTopics; +import org.apache.storm.kafka.spout.KafkaSpoutTupleBuilder; +import org.apache.storm.kafka.spout.KafkaSpoutTuplesBuilder; +import org.apache.storm.kafka.spout.KafkaSpoutTuplesBuilderNamedTopics; +import org.apache.storm.kafka.spout.trident.KafkaTridentSpoutManager; +import org.apache.storm.kafka.spout.trident.KafkaTridentSpoutOpaque; +import org.apache.storm.trident.Stream; +import org.apache.storm.trident.TridentState; +import org.apache.storm.trident.TridentTopology; +import org.apache.storm.trident.operation.builtin.Count; +import org.apache.storm.trident.operation.builtin.Debug; +import org.apache.storm.trident.testing.Split; +import org.apache.storm.tuple.Fields; +import org.apache.storm.tuple.Values; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +import static org.apache.storm.kafka.spout.KafkaSpoutConfig.FirstPollOffsetStrategy.EARLIEST; + +public class TridentKafkaClientWordCountNamedTopics extends TridentKafkaWordCount { + public TridentKafkaClientWordCountNamedTopics(String zkUrl, String brokerUrl) { + super(zkUrl, brokerUrl); + } + + protected TridentState addTridentState(TridentTopology tridentTopology) { + final Stream spoutStream = tridentTopology.newStream("spout1", createOpaqueKafkaSpoutNew()).parallelismHint(1); + + return spoutStream.each(spoutStream.getOutputFields(), new Debug(true)) + .each(new Fields("str"), new Split(), new Fields("word")) + .groupBy(new Fields("word")) + .persistentAggregate(new DebugMemoryMapState.Factory(), new Count(), new Fields("count")); + } + + private KafkaTridentSpoutOpaque<String, String> createOpaqueKafkaSpoutNew() { + return new KafkaTridentSpoutOpaque<String, String>(getKafkaTridentManager()); --- End diff -- Partially Done in refactored examples in this [PR](https://github.com/apache/storm/pull/1757). There were some redundant "factory methods" that I removed. However, the code creating the "dependency" objects that need to be passed in is not 1 or two lines. I believe that a method with a meaningful name creating and initializing these "dependency" objects makes the code much more cohesive and easier to read. Furthermore, this class is extended for wildcard topics, and some of these methods overridden. I will be happy to write a more "copy" and "paste" like example in the docs if you feel it's appropriate. Please let me know.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---