implicit ids and multiple values auto emit
This commit is contained in:
parent
96fa35ab50
commit
f57d0506ed
|
@ -4,14 +4,14 @@ require 'examples/simple/split_sentence_bolt'
|
|||
require 'examples/simple/word_count_bolt'
|
||||
|
||||
class LocalWordCountTopology < RedStorm::SimpleTopology
|
||||
spout RandomSentenceSpout, :id => 1, :parallelism => 5
|
||||
spout RandomSentenceSpout, :parallelism => 5
|
||||
|
||||
bolt SplitSentenceBolt, :id => 2, :parallelism => 8 do
|
||||
source 1, :shuffle
|
||||
bolt SplitSentenceBolt, :parallelism => 8 do
|
||||
source RandomSentenceSpout, :shuffle
|
||||
end
|
||||
|
||||
bolt WordCountBolt, :id => 3, :parallelism => 12 do
|
||||
source 2, :fields => ["word"]
|
||||
bolt WordCountBolt, :parallelism => 12 do
|
||||
source SplitSentenceBolt, :fields => ["word"]
|
||||
end
|
||||
|
||||
configure :word_count do |env|
|
||||
|
|
|
@ -1,4 +1,29 @@
|
|||
class SplitSentenceBolt < RedStorm::SimpleBolt
|
||||
output_fields :word
|
||||
on_receive(:emit => false) {|tuple| tuple.getString(0).split(' ').each {|w| emit(w)}}
|
||||
|
||||
# block declaration style no auto-emit
|
||||
#
|
||||
# on_receive :emit => false do |tuple|
|
||||
# tuple.getString(0).split(' ').each{|w| emit(w)}
|
||||
# end
|
||||
|
||||
# block declaration style with auto-emit
|
||||
#
|
||||
on_receive do |tuple|
|
||||
tuple.getString(0).split(' ').map{|w| [w]}
|
||||
end
|
||||
|
||||
# alternate declaration style using on_receive method
|
||||
#
|
||||
# on_receive :emit => false
|
||||
# def on_receive(tuple)
|
||||
# tuple.getString(0).split(' ').each {|w| emit(w)}
|
||||
# end
|
||||
|
||||
# alternate declaration style using any specific method
|
||||
#
|
||||
# on_receive :my_method, :emit => false
|
||||
# def my_method(tuple)
|
||||
# tuple.getString(0).split(' ').each {|w| emit(w)}
|
||||
# end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue