Upon a TitanException in your load() method, you could wrap it in an 
IOException and re-throw, and rather than print the stack trace, you can catch 
the IOException in onTrigger() and send to failure. You likely won't want to 
rollback the session if you're transferring to failure; the user can choose to 
route the failure relationship however they want (perhaps back to the 
processor). However you probably want to penalize the flow file since it causes 
the error.

If the TitanException can be caused by network issues or something not related 
to the flow file content itself, you may want to throw various types of 
Exceptions and route the those flow files who are impacted by non-flowfile 
related errors) to a "retry" relationship, indicating that the same operation 
may work at a later time.

Regards,
Matt


> On Apr 13, 2016, at 6:14 AM, idioma <[email protected]> wrote:
> 
> Hi,
> I have a custom Apache NiFi processor whose aim is to load a sample graph
> into Titan Db. I have a load method that creates the graph with a few
> vertices/edges and commits the transaction (transaction.commit() is wrapped
> around a try/catch block to catch any TitanException). Inside my On Trigger
> I have the following:
> 
> @Override
>    public void onTrigger(final ProcessContext context, final ProcessSession
> session) throws ProcessException {
> 
>        FlowFile flowFile = session.get();
>        if (flowFile == null) return;
> 
>        session.read(flowFile, new InputStreamCallback() {
> 
>            @Override
>            public void process(InputStream in) throws IOException {
> 
>                StringWriter strWriter = new StringWriter();
>                IOUtils.copy(in, strWriter, "UTF-8");
>                String contents = strWriter.toString();
> 
>                try {
>                    load(contents);
>                } catch (IOException e) {
>                    e.printStackTrace();
>                }
>            }
>        });
> }
> 
> The load method takes a string, which is the conversion from the InpuStream.
> I am trying to find a way to, according to the commit being successfully or
> not, jump into a session.rollback(true); session.transfer(flowFile, FAILURE)
> or session.transfer(flowFile, SUCCESS)
> 
> Can you help please?
> 
> 
> 
> --
> View this message in context: 
> http://apache-nifi-developer-list.39713.n7.nabble.com/catch-commit-error-in-OnTrigger-to-diversify-session-behaviour-tp9027.html
> Sent from the Apache NiFi Developer List mailing list archive at Nabble.com.

Reply via email to