我正在尝试使用 NiFi ExecuteScript 将消息发布到使用 Python 的 irc 聊天室。我是否使用正确的语法将流文件从队列传递到处理器?NameError 导致处理器错误:未定义全局名称“服务器”,但我不确定是什么原因造成的。在我添加 session.get() 之前,一切似乎都有效。
import socket
from org.apache.nifi.processor.io import StreamCallback, InputStreamCallback
class PyStreamCallback(InputStreamCallback):
def __init__(self):
pass
self.ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.server = "irc.freenode.net"
self.channel = ""
self.botnick = ""
self.ircsock.connect((server, 6667))
self.ircsock.send(bytes("USER "+ botnick +" "+ botnick +" "+ botnick + " " + botnick + "\n"))
self.ircsock.send(bytes("NICK "+ botnick +"\n"))
def joinchan(self, chan):
self.ircsock.send(bytes("JOIN "+ chan +"\n"))
ircmsg = ""
while ircmsg.find("End of /NAMES list.") == -1:
self.ircmsg = ircsock.recv(2048)
self.ircmsg = ircmsg.strip('\n\r')
print(ircmsg)
def sendmsg(self, msg, target=channel):
self.ircsock.send(bytes("PRIVMSG "+ target +" :"+ msg +"\n"))
flowFile = session.get()
if (flowFile != None):
flowFile = session.read(flowFile,PyStreamCallback())
session.commit()