本文整理匯總了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"));
}