本文整理汇总了Java中storm.kafka.SpoutConfig类的典型用法代码示例。如果您正苦于以下问题:Java SpoutConfig类的具体用法?Java SpoutConfig怎么用?Java SpoutConfig使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SpoutConfig类属于storm.kafka包,在下文中一共展示了SpoutConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: constructKafkaSpoutConf
import storm.kafka.SpoutConfig; //导入依赖的package包/类
private SpoutConfig constructKafkaSpoutConf() {
// BrokerHosts hosts = new ZkHosts(topologyConfig.getProperty("kafka.zookeeper.host.port"));
BrokerHosts hosts = new ZkHosts("localhost:2181");
/*
String topic = topologyConfig.getProperty("kafka.topic");
String zkRoot = topologyConfig.getProperty("kafka.zkRoot");
String consumerGroupId = topologyConfig.getProperty("kafka.consumer.group.id");
*/
String topic = "addresses";
String zkRoot = "";
String consumerGroupId = "group1";
SpoutConfig spoutConfig = new SpoutConfig(hosts, topic, zkRoot, consumerGroupId);
spoutConfig.scheme = new SchemeAsMultiScheme(new StringScheme());
return spoutConfig;
}
示例2: configureKafkaSpout
import storm.kafka.SpoutConfig; //导入依赖的package包/类
public static void configureKafkaSpout(TopologyBuilder builder, String zkHostString, String kafkaTopic,
String kafkaStartOffset, int parallelismHint, String spoutName,
String spoutScheme) {
LOG.info("KAFKASPOUT: Configuring the KafkaSpout");
// Configure the KafkaSpout
SpoutConfig spoutConfig = new SpoutConfig(new ZkHosts(zkHostString),
kafkaTopic, // Kafka topic to read from
"/" + kafkaTopic, // Root path in Zookeeper for the spout to store consumer offsets
UUID.randomUUID().toString()); // ID for storing consumer offsets in Zookeeper
try {
spoutConfig.scheme = new SchemeAsMultiScheme(getSchemeFromClassName(spoutScheme));
} catch(Exception e) {
LOG.error("ERROR: Unable to create instance of scheme: " + spoutScheme);
e.printStackTrace();
}
setKafkaOffset(spoutConfig, kafkaStartOffset);
KafkaSpout kafkaSpout = new KafkaSpout(spoutConfig);
// Add the spout and bolt to the topology
builder.setSpout(spoutName, kafkaSpout, parallelismHint);
}
示例3: testOpen
import storm.kafka.SpoutConfig; //导入依赖的package包/类
@Test
public void testOpen(
final @Injectable SpoutConfig spoutConfig,
final @Injectable Map conf,
final @Injectable TopologyContext context,
final @Injectable SpoutOutputCollector collector,
final @Injectable KafkaSpout kafkaSpout) throws Exception {
spout.rateLimiter = null;
spout.kafkaSpout = kafkaSpout;
new Expectations(spout) {{
spout.setupKafkaSpout();
}};
spout.permitsPerSecond = spout.DEFAULT_PERMITS_PER_SECOND;
spout.open(conf, context, collector);
Assert.assertNull(spout.rateLimiter);
spout.permitsPerSecond = 1D;
spout.open(conf, context, collector);
Assert.assertNotNull(spout.rateLimiter);
}
示例4: buildTopology
import storm.kafka.SpoutConfig; //导入依赖的package包/类
public StormTopology buildTopology(Properties properties) {
// Load properties for the storm topology
String kafkaTopic = properties.getProperty("kafka.topic");
SpoutConfig kafkaConfig = new SpoutConfig(kafkaBrokerHosts, kafkaTopic, "", "storm");
kafkaConfig.scheme = new SchemeAsMultiScheme(new StringScheme());
TopologyBuilder builder = new TopologyBuilder();
// Specific audit logs analysis bolts
AuditLoginsCounterBolt loginCounterbolt = new AuditLoginsCounterBolt();
AuditParserBolt auditParserBolt = new AuditParserBolt();
// Elastic search bolt
TupleMapper tupleMapper = new DefaultTupleMapper();
ElasticSearchBolt elasticSearchBolt = new ElasticSearchBolt(tupleMapper);
// Topology scheme: KafkaSpout -> auditParserBolt -> loginCounterBolt -> elasticSearchBolt
builder.setSpout("KafkaSpout", new KafkaSpout(kafkaConfig), 1);
builder.setBolt("ParseBolt", auditParserBolt, 1).shuffleGrouping("KafkaSpout");
builder.setBolt("CountBolt", loginCounterbolt, 1).shuffleGrouping("ParseBolt");
builder.setBolt("ElasticSearchBolt", elasticSearchBolt, 1)
.fieldsGrouping("CountBolt", new Fields("id", "index", "type", "document"));
return builder.createTopology();
}
示例5: configureKafkaSpout
import storm.kafka.SpoutConfig; //导入依赖的package包/类
public static void configureKafkaSpout(TopologyBuilder builder, String zkHostString, String kafkaTopic, String kafkaStartOffset) {
// Configure the KafkaSpout
SpoutConfig spoutConfig = new SpoutConfig(new ZkHosts(zkHostString),
kafkaTopic, // Kafka topic to read from
"/" + kafkaTopic, // Root path in Zookeeper for the spout to store consumer offsets
UUID.randomUUID().toString()); // ID for storing consumer offsets in Zookeeper
//spoutConfig.scheme = new SchemeAsMultiScheme(new StringScheme());
spoutConfig.scheme = new SchemeAsMultiScheme(new JsonScheme());
// Allow for passing in an offset time
// startOffsetTime has a bug that ignores the special -2 value
if(kafkaStartOffset == "-2") {
spoutConfig.forceFromStart = true;
} else if (kafkaStartOffset != null) {
spoutConfig.startOffsetTime = Long.parseLong(kafkaStartOffset);
}
KafkaSpout kafkaSpout = new KafkaSpout(spoutConfig);
// Add the spout and bolt to the topology
builder.setSpout("kafkaspout", kafkaSpout, 1);
}
示例6: initializeKafkaSpout
import storm.kafka.SpoutConfig; //导入依赖的package包/类
private boolean initializeKafkaSpout(String name) {
try {
BrokerHosts zk = new ZkHosts(config.getString("kafka.zk"));
String input_topic = config.getString("spout.kafka.topic");
SpoutConfig kafkaConfig = new SpoutConfig(zk, input_topic, "",
input_topic);
kafkaConfig.scheme = new SchemeAsMultiScheme(new RawScheme());
kafkaConfig.forceFromStart = Boolean.valueOf("True");
kafkaConfig.startOffsetTime = -1;
builder.setSpout(name, new KafkaSpout(kafkaConfig),
config.getInt("spout.kafka.parallelism.hint")).setNumTasks(
config.getInt("spout.kafka.num.tasks"));
} catch (Exception e) {
e.printStackTrace();
System.exit(0);
}
return true;
}
示例7: constructKafkaSpoutConf
import storm.kafka.SpoutConfig; //导入依赖的package包/类
/**
* Construct
* @return
*/
private SpoutConfig constructKafkaSpoutConf() {
BrokerHosts hosts = new ZkHosts(topologyConfig.getProperty("kafka.zookeeper.host.port"));
String topic = topologyConfig.getProperty("kafka.topic");
String zkRoot = topologyConfig.getProperty("kafka.zkRoot");
String consumerGroupId = topologyConfig.getProperty("kafka.consumer.group.id");
SpoutConfig spoutConfig = new SpoutConfig(hosts, topic, zkRoot, consumerGroupId);
/* Custom TruckScheme that will take Kafka message of single truckEvent
* and emit a 2-tuple consisting of truckId and truckEvent. This driverId
* is required to do a fieldsSorting so that all driver events are sent to the set of bolts */
spoutConfig.scheme = new SchemeAsMultiScheme(new TruckScheme2());
return spoutConfig;
}
示例8: main
import storm.kafka.SpoutConfig; //导入依赖的package包/类
public static void main(String[] args) {
TopologyBuilder builder = new TopologyBuilder();
SpoutConfig spoutConf = new SpoutConfig(new ZkHosts("localhost:2181", "/brokers"), "test", "/kafkastorm", "KafkaSpout");
spoutConf.scheme = new SchemeAsMultiScheme(new StringScheme());
spoutConf.forceFromStart = true;
builder.setSpout("KafkaSpout", new KafkaSpout(spoutConf), 3);
builder.setBolt("KafkaBolt", new PrinterBolt(), 3).shuffleGrouping("KafkaSpout");
Config conf = new Config();
// conf.setDebug(true);
LocalCluster cluster = new LocalCluster();
cluster.submitTopology("kafka-test", conf, builder.createTopology());
Utils.sleep(60000);
cluster.shutdown();
}
示例9: main
import storm.kafka.SpoutConfig; //导入依赖的package包/类
public static void main(String[] args) {
Config conf = new Config();
// conf.put(Config.TOPOLOGY_DEBUG,true);
conf.put(StormElasticSearchConstants.ES_CLUSTER_NAME,"elasticsearch");
conf.put(StormElasticSearchConstants.ES_HOST,"localhost");
conf.put(StormElasticSearchConstants.ES_PORT,9300);
ZkHosts zooHosts = new ZkHosts("localhost:50003");
TopologyBuilder builder = new TopologyBuilder();
SpoutConfig spoutConfig = new SpoutConfig(zooHosts, "test", "", "STORM-ID");
//spoutConfig.scheme=new StringScheme();
// spoutConfig.scheme = new SchemeAsMultiScheme(new StringScheme());
KafkaSpout spout1 = new KafkaSpout(spoutConfig);
builder.setSpout("source", spout1, 1);
builder.setBolt("echo", new EchoBolt(), 1).shuffleGrouping("source");
LocalCluster cluster = new LocalCluster();
cluster.submitTopology("basic_primitives", conf,
builder.createTopology());
}
示例10: main
import storm.kafka.SpoutConfig; //导入依赖的package包/类
/**
* @param args
* http://www.programcreek.com/java-api-examples/index.php?api=storm.kafka.KafkaSpout
*/
public static void main(String[] args) {
try{
//设置喷发节点并分配并发数,该并发数将会控制该对象在集群中的线程数(6个)
String zkhost = "wxb-1:2181,wxb-2:2181,wxb-3:2181";
String topic = "order";
String groupId = "id";
int spoutNum = 3;
int boltNum = 1;
ZkHosts zkHosts = new ZkHosts(zkhost);//kafaka所在的zookeeper
SpoutConfig spoutConfig = new SpoutConfig(zkHosts, topic, "/order", groupId); // create /order /id
spoutConfig.scheme = new SchemeAsMultiScheme(new StringScheme());
KafkaSpout kafkaSpout = new KafkaSpout(spoutConfig);
TopologyBuilder builder = new TopologyBuilder();
builder.setSpout("spout", kafkaSpout, spoutNum);
builder.setBolt("check", new CheckOrderBolt(), boltNum).shuffleGrouping("spout");
builder.setBolt("counter", new CounterBolt(),boltNum).shuffleGrouping("check");
Config config = new Config();
config.setDebug(true);
if(args!=null && args.length > 0) {
config.setNumWorkers(2);
StormSubmitter.submitTopology(args[0], config, builder.createTopology());
} else {
config.setMaxTaskParallelism(2);
LocalCluster cluster = new LocalCluster();
cluster.submitTopology("Wordcount-Topology", config, builder.createTopology());
Thread.sleep(500000);
cluster.shutdown();
}
}catch (Exception e) {
e.printStackTrace();
}
}
示例11: constructKafkaSpoutConf
import storm.kafka.SpoutConfig; //导入依赖的package包/类
private SpoutConfig constructKafkaSpoutConf() {
// BrokerHosts hosts = new ZkHosts(topologyConfig.getProperty("kafka.zookeeper.host.port"));
BrokerHosts hosts = new ZkHosts("localhost:2181");
String topic = "properties";
String zkRoot = "";
String consumerGroupId = "group1";
SpoutConfig spoutConfig = new SpoutConfig(hosts, topic, zkRoot, consumerGroupId);
spoutConfig.scheme = new SchemeAsMultiScheme(new StringScheme());
return spoutConfig;
}
示例12: getKafkaSpout
import storm.kafka.SpoutConfig; //导入依赖的package包/类
public KafkaSpout getKafkaSpout() {
LOG.info("KAFKASPOUT: Configuring the Kafka Spout");
// Create the initial spoutConfig
SpoutConfig spoutConfig = new SpoutConfig(new ZkHosts(zookeeperConnectionString),
kafkaTopic, // Kafka topic to read from
"/" + kafkaTopic, // Root path in Zookeeper for the spout to store consumer offsets
UUID.randomUUID().toString()); // ID for storing consumer offsets in Zookeeper
// Set the scheme
try {
spoutConfig.scheme = new SchemeAsMultiScheme(getSchemeFromClassName(spoutSchemeClass));
} catch(Exception e) {
LOG.error("ERROR: Unable to create instance of scheme: " + spoutSchemeClass);
e.printStackTrace();
}
// Set the offset
setKafkaOffset(spoutConfig, kafkaStartOffset);
// Create the kafkaSpout
return new KafkaSpout(spoutConfig);
}
示例13: setKafkaOffset
import storm.kafka.SpoutConfig; //导入依赖的package包/类
private static void setKafkaOffset(SpoutConfig spoutConfig, String kafkaStartOffset) {
// Allow for passing in an offset time
// startOffsetTime has a bug that ignores the special -2 value
if(kafkaStartOffset.equals("-2")) {
spoutConfig.startOffsetTime = kafka.api.OffsetRequest.EarliestTime();
} else if (kafkaStartOffset != null) {
spoutConfig.startOffsetTime = Long.parseLong(kafkaStartOffset);
}
}
示例14: constructKafkaSpoutConf
import storm.kafka.SpoutConfig; //导入依赖的package包/类
private SpoutConfig constructKafkaSpoutConf() {
BrokerHosts hosts = new ZkHosts(topologyConfig.getProperty("kafka.zookeeper.host.port"));
String topic = topologyConfig.getProperty("kafka.topic");
String zkRoot = topologyConfig.getProperty("kafka.zkRoot");
String consumerGroupId = topologyConfig.getProperty("kafka.consumer.group.id");
SpoutConfig spoutConfig = new SpoutConfig(hosts, topic, zkRoot, consumerGroupId);
/* Custom TruckScheme that will take Kafka message of single truckEvent
* and emit a 2-tuple consisting of truckId and truckEvent. This driverId
* is required to do a fieldsSorting so that all driver events are sent to the set of bolts */
spoutConfig.scheme = new SchemeAsMultiScheme(new TruckScheme2());
return spoutConfig;
}
示例15: main
import storm.kafka.SpoutConfig; //导入依赖的package包/类
public static void main(String[] args) throws AlreadyAliveException, InvalidTopologyException {
String zkIp = "localhost";
String nimbusHost = "sandbox.hortonworks.com";
String zookeeperHost = zkIp +":2181";
ZkHosts zkHosts = new ZkHosts(zookeeperHost);
List<String> zkServers = new ArrayList<String>();
zkServers.add(zkIp);
SpoutConfig kafkaConfig = new SpoutConfig(zkHosts, "spertus-flight-events", "/spertus-flights-events","flight_id");
kafkaConfig.scheme = new SchemeAsMultiScheme(new StringScheme());
kafkaConfig.startOffsetTime = kafka.api.OffsetRequest.EarliestTime();
kafkaConfig.zkServers = zkServers;
kafkaConfig.zkRoot = "/spertus-flight-events";
kafkaConfig.zkPort = 2181;
kafkaConfig.forceFromStart = true;
KafkaSpout kafkaSpout = new KafkaSpout(kafkaConfig);
TopologyBuilder builder = new TopologyBuilder();
builder.setSpout("flight-events", kafkaSpout, 1);
builder.setBolt("flight-stats", new GetFlightStatsBolt(), 1).shuffleGrouping("flight-events");
Map conf = new HashMap();
conf.put(backtype.storm.Config.TOPOLOGY_WORKERS, 4);
conf.put(backtype.storm.Config.TOPOLOGY_DEBUG, true);
if (args != null && args.length > 0) {
StormSubmitter.submitTopology(args[0], conf, builder.createTopology());
} else {
LocalCluster cluster = new LocalCluster();
cluster.submitTopology("flight-topology", conf, builder.createTopology());
}
}