gpt4 book ai didi

python - 在 executeScript NIFI python 中使用 FlowFile 属性

转载 作者:太空宇宙 更新时间:2023-11-04 03:00:37 28 4
gpt4 key购买 nike

我试图在我的 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)

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

最佳答案

它们不会立即在 process 方法中可用,除非您执行某些操作,例如将对 FlowFile 的引用传递到您的 TransformCallback 构造函数中。另一种选择是将读取和写入(因为您正在使用 IOUtils.toString() 一次读取整个内容)拆分为两个单独的调用,然后您可以在 process() 方法之外进行属性操作。

顺便说一句,如果您只需要将整个内容作为字符串读入,则不需要 StreamCallback 或 InputStreamCallback,您可以使用返回 InputStream 的 session.read(flowFile)(而不是执行提供的打回来)。您可以在上面调用 IOUtils.toString() (并且不要忘记之后关闭它),从而避免回调并允许使用当前的 FlowFile 引用(以及 getAttribute() 或 getAttributes()方法)。

关于python - 在 executeScript NIFI python 中使用 FlowFile 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41023061/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com