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

查看:158
本文介绍了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. 我想从文件夹中获取文件以读取其数据并将其作为属性添加到新的流文件中,然后将config 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); 如果(attributes.size()> 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?

推荐答案

在这里回答,我不相信此用例需要定制处理器开发.将GetHDFS保留源文件:true设置一起使用,以将文件保持在原始位置,并将ExecuteXPath与各种XPath值一起使用,以将内容中的数据提取到flowfile属性中.您还可以结合使用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天全站免登陆