1
Apache Storm Spout을 파일별로 한 줄씩 읽으려고합니다. 이 진술을 쓰려고했지만 작동하지 않았습니다. 그것은 나를 첫 번째 줄은 매번 반복했다 :Apache Storm 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()
감사합니다. 두 번째 질문은 제거했지만 코드는 첫 번째 줄만 입력 했으므로 파일에 많이 들어 있습니다. – user5520049
전체 파일을 수행하는 루프를 추가하도록 편집했습니다. –
도움 주셔서 감사합니다,하지만 java.lang.RuntimeException있어 : backtype.storm.multilang.NoOutputException : 파이프 하위 프로세스가 손상된 것 같습니다! 출력을 읽지 않습니다. 시리얼 예외 : 파일 "simspout.py", 라인 (22) storm.logInfo ("내뿜는 냉온 %의"% 선) ^ IndentationError : 들여 쓰기 블록 – user5520049