本文整理汇总了Java中org.p7h.storm.sentimentanalysis.spouts.TwitterSpout类的典型用法代码示例。如果您正苦于以下问题:Java TwitterSpout类的具体用法?Java TwitterSpout怎么用?Java TwitterSpout使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TwitterSpout类属于org.p7h.storm.sentimentanalysis.spouts包,在下文中一共展示了TwitterSpout类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.p7h.storm.sentimentanalysis.spouts.TwitterSpout; //导入依赖的package包/类
public static final void main(final String[] args) throws Exception {
final ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
final JmsProvider jmsProvider = new SpringJmsProvider(applicationContext, "jmsConnectionFactory",
"notificationQueue");
final TopologyBuilder topologyBuilder = new TopologyBuilder();
final JmsBolt jmsBolt = new JmsBolt();
jmsBolt.setJmsProvider(jmsProvider);
jmsBolt.setJmsMessageProducer((session, input) -> {
final String json = "{\"stateCode\":\"" + input.getString(0) + "\", \"sentiment\":" + input.getInteger(1) + "}";
return session.createTextMessage(json);
});
try {
final Config config = new Config();
config.setMessageTimeoutSecs(120);
config.setDebug(true);
topologyBuilder.setSpout("twitterspout", new TwitterSpout());
topologyBuilder.setBolt("statelocatorbolt", new StateLocatorBolt())
.shuffleGrouping("twitterspout");
topologyBuilder.setBolt("sentimentcalculatorbolt", new SentimentCalculatorBolt())
.fieldsGrouping("statelocatorbolt", new Fields("state"));
topologyBuilder.setBolt("jmsBolt", jmsBolt).fieldsGrouping("sentimentcalculatorbolt", new Fields("stateCode"));
//Submit it to the cluster, or submit it locally
if (null != args && 0 < args.length) {
config.setNumWorkers(3);
StormSubmitter.submitTopology(args[0], config, topologyBuilder.createTopology());
} else {
config.setMaxTaskParallelism(10);
final LocalCluster localCluster = new LocalCluster();
localCluster.submitTopology(Constants.TOPOLOGY_NAME, config, topologyBuilder.createTopology());
//Run this topology for 600 seconds so that we can complete processing of decent # of tweets.
Utils.sleep(600 * 1000);
LOGGER.info("Shutting down the cluster...");
localCluster.killTopology(Constants.TOPOLOGY_NAME);
localCluster.shutdown();
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
LOGGER.info("Shutting down the cluster...");
localCluster.killTopology(Constants.TOPOLOGY_NAME);
localCluster.shutdown();
}
});
}
} catch (final Exception exception) {
//Deliberate no op;
exception.printStackTrace();
}
LOGGER.info("\n\n\n\t\t*****Please clean your temp folder \"{}\" now!!!*****", System.getProperty("java.io.tmpdir"));
}