简体   繁体   English

如何在Python中使用NiFi ExecuteScript处理器?

[英]How to use NiFi ExecuteScript processor with Python?

I have a very basic setup of the ExecuteScript processor in Apache NiFi with a simple Python script (saved as a .py file) as shown here. 我在Apache NiFi中有一个非常基本的ExecuteScript处理器设置,带有一个简单的Python脚本(保存为.py文件),如下所示。 In the Properties of the processor, I set the Script Engine to python and Script File to the path of this script. 在处理器的属性中,我将脚本引擎设置为python,将脚本文件设置为此脚本的路径。

import time

count = 0

while(count < 20):
    print "The counter says: ", count
    count = count + 1
    time.sleep(.1)

And this is the dataflow diagram I made: 这是我制作的数据流图: nifi数据流

I don't see anything outputted to the log or the PutFile. 我没有看到输出到日志或PutFile的任何内容。 However, I do see the print statements appear in \\nifi-0.6.1\\logs\\nifi-bootstrap.log. 但是,我确实看到打印语句出现在\\ nifi-0.6.1 \\ logs \\ nifi-bootstrap.log中。 My knowledge of this is currently limited. 我对此的了解目前有限。 I would appreciate answers from anyone who knows how to use the ExecuteScript processor, or even give me a better example than my current setup. 我很感激任何知道如何使用ExecuteScript处理器的人的答案,或者甚至比我当前的设置给出一个更好的例子。

Given your script, I think everything is functioning as expected. 鉴于您的脚本,我认为一切都按预期运行。 The script is not producing any FlowFiles which is why nothing is moving from ExecuteScript to the other processors, and anything sent to system out is captured in the bootstrap.log so that is why the print statement ends up there. 该脚本不生成任何FlowFiles,这就是为什么没有任何东西从ExecuteScript移动到其他处理器,并且发送到系统的任何内容都在bootstrap.log中捕获,这就是print语句结束的原因。

Script executing with in ExecuteScript get access to a few standard objects: 使用ExecuteScript执行的脚本可以访问一些标准对象:

  • session 会议
  • context 上下文
  • log 日志
  • REL_FAILURE REL_FAILURE
  • REL_SUCCESS REL_SUCCESS

In order to produce FlowFiles you would need call session.create() and take the resulting FlowFile and transfer it to REL_SUCCESS. 为了生成FlowFiles,您需要调用session.create()并获取生成的FlowFile并将其传输到REL_SUCCESS。

The best source of info on the scripting processors is Matt Burgess's blog, this page has some good background (uses Groovy): 脚本处理器的最佳信息来源是Matt Burgess的博客,这个页面有一些很好的背景(使用Groovy):

http://funnifi.blogspot.com/2016/02/executescript-processor-hello-world.html http://funnifi.blogspot.com/2016/02/executescript-processor-hello-world.html

This one has a Jython example: 这个有一个Jython示例:

http://funnifi.blogspot.com/2016/03/executescript-json-to-json-revisited_14.html http://funnifi.blogspot.com/2016/03/executescript-json-to-json-revisited_14.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 带有 Python 引擎的 Nifi ExecuteScript 处理器不记录信息 - Nifi ExecuteScript Processor with Python engine not logging info 如何在apache nifi中的ExecuteScript处理器中编写pythoncode? - How to write pythoncode in ExecuteScript processor in apache nifi? 如何在nifi中执行script python脚本 - how to executescript python script in nifi 无法从Nifi ExecuteScript处理器引用python库 - Unable to refer python libraries from Nifi ExecuteScript processor 如何在NiFi UI中为ExecuteScript处理器启用“查看状态”选项? - How to enable “View State” option for ExecuteScript processor in NiFi UI? 使用Nifi ExecuteScript处理器生成多个流文件 - Generating multiple flowfiles using the Nifi ExecuteScript processor 尽管python代码正确,但从nifi ExecuteScript处理器中获取语法错误 - getting syntax error from nifi ExecuteScript processor inspite of correct python code 如何在没有前缀&#39;u&#39;代码的情况下python Nifi ExecuteScript返回属性? - How to Nifi ExecuteScript return attribute without prefix 'u' code python? 如何使用Python在Nifi中编写自定义处理器? - How to write a customized processor in Nifi using Python? Apache NiFi:使用 ExecuteScript 处理器处理多个 csv - Apache NiFi: Processing multiple csv's using the ExecuteScript Processor
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM