【发布时间】:2017-04-04 08:51:51
【问题描述】:
在这个问题上我需要你的帮助。我读到 spout 负责读取数据或准备在 Bolt 中处理。所以我在 spout 中写了一些代码来打开文件并逐行读取
class SimSpout(storm.Spout):
# Not much to do here for such a basic spout
def initialize(self, conf, context):
## Open the file with read only permit
self.f = open('data.txt', 'r')
## Read the first line
self._conf = conf
self._context = context
storm.logInfo("Spout instance starting...")
# Process the next tuple
def nextTuple(self):
# check if it reach at the EOF to close it
for line in self.f.readlines():
# Emit a random sentence
storm.logInfo("Emiting %s" % line)
storm.emit([line])
# Start the spout when it's invoked
SimSpout().run()
对吗?
【问题讨论】:
标签: python apache-storm