当前位置: 首页>>代码示例>>Java>>正文


Java TwitterSpout类代码示例

本文整理汇总了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"));
}
 
开发者ID:P7h,项目名称:StormTweetsSentimentD3UKViz,代码行数:58,代码来源:SentimentAnalysisTopology.java


注:本文中的org.p7h.storm.sentimentanalysis.spouts.TwitterSpout类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。