Creating a Storm Spout
Function Description
A Spout is a message source of Storm and message producer of the topology. Generally, a message source reads data from an external source and sends messages (Tuple) to the topology.
One message source can send multiple message streams, and therefore, OutputFieldsDeclarer.declarerStream can be used to define multiple streams, and then SpoutOutputCollector emits specific streams.
Sample Code
The following code snippet belongs to the nextTuple method in the RandomSentenceSpout class of the com.huawei.storm.example.common package, and these code snippets are used to split strings into words.
/** * {@inheritDoc} */ @Override public void nextTuple() { Utils.sleep(100); String[] sentences = new String[] {"the cow jumped over the moon", "an apple a day keeps the doctor away", "four score and seven years ago", "snow white and the seven dwarfs", "i am at two with nature"}; String sentence = sentences[random.nextInt(sentences.length)]; collector.emit(new Values(sentence)); }
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot