Nifi:编写新的处理器 [英] Nifi:Writing new Processors

查看:37
本文介绍了Nifi:编写新的处理器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作新的处理器,它将是 GetFile 和 EvaluateXpath 的重聚,有几个我感兴趣的主题:

I want to make new processor which will be the reunion of GetFile and EvaluateXpath there are several subject i am interested in:

  1. 如果我的 nar 文件超过 20kb 并且我的 nifi 无法运行它,我该如何缩小它?
  2. 我想从文件夹中获取文件读取它的数据并将其作为属性放入新的流文件中,然后将配置 xml 回滚到它的原始文件夹,如何将我的配置文件回滚到文件夹 b 代码?
  3. 这是我用来从 xml 配置文件获取属性的简单代码:

  1. How can i shrink my nar file now it is more than 20kb and my nifi can't run it?
  2. I want to get File from folder read it's data and put it as an atribute inside new flowfile,then rolling back config xml to it's original folder , how can i roll my config file back to folder b code?
  3. Here is simple code i use for getting attributes from xml config file :

XPathExpression start = xpath.compile("//*[local-name()='start']");
                XPathExpression startDate = xpath.compile("//*[local-name()='startDate']");
                XPathExpression endDate = xpath.compile("//*[local-name()='endDate']");
                XPathExpression runAs = xpath.compile("//*[local-name()='run']");
                XPathExpression patch = xpath.compile("//*[local-name()='patch Information']");
Object resultStart = start.evaluate(doc, XPathConstants.STRING);
                NodeList nodes = (NodeList) resultStart;
                flowFile = session.putAttribute(flowFile, "start", String.valueOf(nodes.item(nodes.getLength()-1)));

地图属性 = getAttributesFromFile(filePath);如果(属性.大小()> 0){flowFile = session.putAllAttributes(flowFile, attributes);}

Map attributes = getAttributesFromFile(filePath); if (attributes.size() > 0) { flowFile = session.putAllAttributes(flowFile, attributes); }

但它不能正常工作,我应该改变什么?

but it does't work properly, what should i change?

推荐答案

如回答这里,我不相信此用例需要定制处理器开发.使用 GetHDFSKeep source file: true 设置将文件保持在原始位置,并使用 ExecuteXPath使用各种 XPath 值从内容中提取数据到流文件属性中.您还可以使用 ListHDFSFetchHDFS 的组合将 XML 文件保存在 HDFS 中,因为 NiFi 将维护关于它已经看到哪些文件的状态.

As answered here, I don't believe this use case requires custom processor development. Use GetHDFS with the Keep source file: true setting to maintain the file in the original location, and use ExecuteXPath with the various XPath values to extract data from the content into flowfile attributes. You can also use the combination of ListHDFS and FetchHDFS to keep the XML file in HDFS because NiFi will maintain state about which files it has seen.

这篇关于Nifi:编写新的处理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆