我试图让Apache Storm spoutle从一个文件中逐行读取。我试着写这些声明,但没用。它给我的第一行只是每次迭代:
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()
免责声明:因为我没有办法测试这个问题,所以这个答案只能通过检查。在
无法保存在
initialize()
中打开的文件句柄。此编辑保存文件句柄,然后使用保存的文件句柄进行读取。它还修复了一些看起来不正确的缩进(我希望如此)。在相关问题 更多 >
编程相关推荐