use of org.apache.storm.kafka.bolt.selector.DefaultTopicSelector in project storm by apache.
the class KafkaBolt method prepare.
@Override
public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) {
//for backward compatibility.
if (mapper == null) {
this.mapper = new FieldNameBasedTupleToKafkaMapper<K, V>();
}
//for backward compatibility.
if (topicSelector == null) {
if (stormConf.containsKey(TOPIC)) {
this.topicSelector = new DefaultTopicSelector((String) stormConf.get(TOPIC));
} else {
throw new IllegalArgumentException("topic should be specified in bolt's configuration");
}
}
producer = new KafkaProducer<>(boltSpecfiedProperties);
this.collector = collector;
}
use of org.apache.storm.kafka.bolt.selector.DefaultTopicSelector in project storm by apache.
the class KafkaProducerTopology method newTopology.
/**
* @param brokerUrl Kafka broker URL
* @param topicName Topic to which publish sentences
* @return A Storm topology that produces random sentences using {@link RandomSentenceSpout} and uses a {@link KafkaBolt} to
* publish the sentences to the kafka topic specified
*/
public static StormTopology newTopology(String brokerUrl, String topicName) {
final TopologyBuilder builder = new TopologyBuilder();
builder.setSpout("spout", new RandomSentenceSpout.TimeStamped(""), 2);
/* The output field of the RandomSentenceSpout ("word") is provided as the boltMessageField
so that this gets written out as the message in the kafka topic. */
final KafkaBolt<String, String> bolt = new KafkaBolt<String, String>().withProducerProperties(newProps(brokerUrl, topicName)).withTopicSelector(new DefaultTopicSelector(topicName)).withTupleToKafkaMapper(new FieldNameBasedTupleToKafkaMapper<>("key", "word"));
builder.setBolt("forwardToKafka", bolt, 1).shuffleGrouping("spout");
return builder.createTopology();
}
Aggregations