在executeScript NIFI python中使用流文件属性

在executeScript NIFI python中使用流文件属性,python,apache-nifi,Python,Apache Nifi,我试图在python脚本中获取流文件的属性,我已完成以下操作: class TransformCallback(StreamCallback): def __init__(self): pass def process(self, inputStream, outputStream): try: # Read input FlowFile content input_text = IOUtils.

我试图在python脚本中获取流文件的属性,我已完成以下操作:

class TransformCallback(StreamCallback):

    def __init__(self):
        pass

    def process(self, inputStream, outputStream):
        try:
            # Read input FlowFile content
            input_text = IOUtils.toString(inputStream, StandardCharsets.UTF_8)
            input_obj = json.loads(input_text)

但是如何在流程方法中访问我的流文件属性呢?

除非将流文件的引用传递到回调构造函数中,否则它们在流程方法中不会立即可用。另一种选择是将读取和写入(因为您使用IOUtils.toString()同时读取整个内容)分成两个单独的调用,然后您可以在process()方法之外执行属性操作

顺便说一句,如果您只需要将整个内容作为字符串读入,则不需要StreamCallback或InputStreamCallback,您可以使用session.read(flowFile)返回InputStream(而不是执行提供的回调)。您可以在此基础上调用IOUtils.toString()(以后不要忘记关闭它),从而避免回调,并允许使用当前的流文件引用(以及getAttribute()或getAttributes()方法)更轻松地访问流文件属性