Nifi:Writing new Processors

2019-08-30 02:50发布

问题:

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

  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)));
    

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

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

回答1:

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.