Databases Reference
In-Depth Information
There is a way to specify topologies in a non-JVM language. Since Storm
topologies are just Thrift structures, and Nimbus is a Thrift daemon,
you can create and submit topologies in any language you want. But this
it out of the scope of this topic.
Nothing new here. Let's see the implementation of NumbersGeneratorSpout .
public class NumberGeneratorSpout extends ShellSpout implements IRichSpout {
public NumberGeneratorSpout ( Integer from , Integer to ) {
super ( "php" , "-f" , "NumberGeneratorSpout.php" , from . toString (), to
. toString ());
}
public void declareOutputFields ( OutputFieldsDeclarer declarer ) {
declarer . declare ( new Fields ( "number" ));
}
public Map < String , Object > getComponentConfiguration () {
return null ;
}
}
As you have probably noticed, this spout extends ShellSpout . This is a special class that
comes with Storm and helps you run and control spouts written in other languages. In
this case, it tells Storm how to execute your PHP script.
The NumberGeneratorSpout PHP script emits tuples to the standard output, and reads
standard input to process acks or fails.
Before going over the implementation of the NumberGeneratorSpout.php script, look in
more detail at how the multilang protocol works.
The spout generates sequential numbers counting from the from parameter up to the
to parameter, passed to the constructor.
Next, look at PrimeNumbersFilterBolt . This class implements the shell mentioned ear-
lier. It tells Storm how to execute your PHP script. Storm provides a special class for
this purpose called ShellBolt , where the only thing you have to do is to indicate how
to run the script and declare the fields that it emits.
public class PrimeNumbersFilterBolt extends ShellBolt implements IRichBolt {
public PrimeNumbersFilterBolt () {
super ( "php" , "-f" , "PrimeNumbersFilterBolt.php" );
}
public void declareOutputFields ( OutputFieldsDeclarer declarer ) {
declarer . declare ( new Fields ( "number" ));
}
}
 
Search WWH ::




Custom Search