Support Questions
Find answers, ask questions, and share your expertise
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

Nifi: how to remove session based on atribute value in nifi

Nifi: how to remove session based on atribute value in nifi

New Contributor

I want to remove session in case i get certain data from file i have code like this,but i got errors "flowfile has already marked for removal", what should i change to get rid of extra errors?

  1. In case of session rollback flowfile will dissapear in queues also?

    2.should i use rollback instead of remove()?

    NodeList childNodes = nodeGettingChanged.getChildNodes();for(int i =0; i != childNodes.getLength();++i){Node child = childNodes.item(i);if(!(child instanceofElement))continue;if(child.getNodeName().equals("runAs")){if(child.getFirstChild().getTextContent()=="false"){
                                    session.remove(flowFile1);File deleteExtraFile =newFile("C://Users//s.tkhilaishvili//Desktop//try2//nifi-1.3.0//1//conf.xml");booleandelete=deleteExtraFile.delete();}else{

    Document finalXmlDocument = xmlDocument; session.write(flowFile1, new StreamCallback() {

    publicvoid process(InputStream inputStream,OutputStream outputStream)throwsIOException{TransformerFactory transformerFactory =TransformerFactory.newInstance();Transformer transformer =null;try{
                            transformer = transformerFactory.newTransformer();}catch(TransformerConfigurationException e){
                            e.printStackTrace();}DOMSource source =newDOMSource(finalXmlDocument);
                        ffStream.close();ByteArrayOutputStream bos =newByteArrayOutputStream();StreamResult result =newStreamResult(bos);try{
                            transformer.transform(source, result);}catch(TransformerException e){
                            e.printStackTrace();}byte[] array = bos.toByteArray();
                session.transfer(flowFile1, REL_SUCCESS);}

Re: Nifi: how to remove session based on atribute value in nifi

It's hard to tell from the formatting of your code above, but if you are executing session.remove(flowFile1) then later trying to transfer it to REL_SUCCESS, you will get that error. You can either change the logic to put the remove/transfer calls into an if-else block, or keep a boolean variable indicating whether the flow file has already been removed, and transfer if it has not been removed. It looks like you already have an if-clause checking the firstChild for "false", perhaps you could put the transfer in an else-clause.

Don't have an account?
Coming from Hortonworks? Activate your account here