never mind.. i got that working .. i just wanted to understand the flow in the invokescripted processor
first i am reading the input stream to JSON slurper identify whether the element name is ORDER or REFUND based on the element name transfer the flow file to appropriate relationship.. i am sketchy about this step since in the examples you have you only have one relationship.. do you have an example where you have multiple realtionship defined.. i might have missed it on the blog. Anuj On Tue, Jul 26, 2016 at 11:28 AM, Anuj Handa <[email protected]> wrote: > Hi Matt, > > To use JSon slurper into the invokeScripted processor do i have to import > any classes, i didnt see any clases in your examples and when i try to use > new JsonSlurper it give me an error unable to resolve class. > > Anuj > > On Thu, Jul 7, 2016 at 11:45 AM, Matt Burgess <[email protected]> wrote: > >> It will be fixed in 0.7.0 [1]. Also you could use >> InvokeScriptedProcessor to replace both the ExecuteScript and >> RouteOnAttribute, since the scripted processor can define the >> relationships and provide the logic to extract the arbitrary JSON >> keys. >> >> Regards, >> Matt >> >> [1] https://issues.apache.org/jira/browse/NIFI-1822 >> >> On Thu, Jul 7, 2016 at 11:21 AM, Bryan Bende <[email protected]> wrote: >> > I think you actually need to use both ExecuteScript and RouteOnAttribute >> > together. >> > >> > The reason is that ExecuteScript only has success and failure >> relationships, >> > so all you can do there is extract the value you are interested in >> (order or >> > refund) and put it in an attribute and route to success, >> > then send it to RouteOnAttribute which can have the dynamic >> relationships. >> > >> > There was a limitation where ExecuteScript could not run concurrent >> tasks, >> > and I know it was fixed, but not sure if it was fixed in 0.6.1 or for >> the >> > next upcoming release (0.7.0) which is happening soon. >> > Maybe someone else can chime about when this was fixed. >> > >> > On Thu, Jul 7, 2016 at 11:13 AM, Anuj Handa <[email protected]> >> wrote: >> >> >> >> Hi Bryan, >> >> >> >> Thats correct i want to route on element name so "ORDER" through one >> and >> >> "REFUND" to another. The reason is based on element name the >> structure of >> >> the JSON could be different so the subsequent processing depends on the >> >> element name. >> >> >> >> Processing thousands of messages per minute which would be better using >> >> RouteonAttribute or ExecuteScript ? Since the entire JSON doc could >> come in >> >> the attribute if i use $.POSTransaction. i would think it would slow >> it >> >> down compared with if the attribute value only has "ORDER" >> >> >> >> Anuj >> >> >> >> >> >> >> >> On Thu, Jul 7, 2016 at 10:59 AM, Bryan Bende <[email protected]> wrote: >> >>> >> >>> Anuj, >> >>> >> >>> Just to clarify, you want to route on the name of the element under >> >>> POSTransaction? Meaning, route "Order" to one place and "Refund" to >> another? >> >>> >> >>> I'm not a JSON Path expert, but I can't come up with a way to get >> just >> >>> an element name from JSON path, it is usually used to get the value >> of a >> >>> known path. >> >>> >> >>> If you used $.POSTransaction. as the expression I think you would get >> >>> back everything under POSTransaction including the "Order" or >> "Refund" >> >>> part, and >> >>> then in RouteOnAttribute you could use expression language to see >> what it >> >>> starts ${yourAttribute:startsWith('Order')} or maybe use contains() >> instead >> >>> of startsWith. >> >>> >> >>> Another completely different option is to use the ExecuteScript >> processor >> >>> to write a Groovy/Jython/etc script that gets the name of the first >> element >> >>> under POSTransaction and adds it as an attribute. >> >>> >> >>> -Bryan >> >>> >> >>> >> >>> On Thu, Jul 7, 2016 at 8:34 AM, Anuj Handa <[email protected]> >> wrote: >> >>>> >> >>>> Hi Folks, >> >>>> >> >>>> I have following two JSON documents and i would like to route them >> based >> >>>> on what the value is. In the below examples its order and refund. i >> want >> >>>> this to be dynamic as i can expect range of values. >> >>>> >> >>>> i was thinking of using EvaluateJsonPath and reading the Value of >> this >> >>>> field in the attribute. i was unable to get what Path expression >> should be . >> >>>> >> >>>> $.POSTransaction.* returns me the entire JSON and not just the Order >> >>>> value >> >>>> >> >>>> is it possible to make it dynamic ? or is there a better/different >> way >> >>>> to do this >> >>>> >> >>>> { >> >>>> "POSTransaction": { >> >>>> "Order": { >> >>>> >> >>>> { >> >>>> "POSTransaction": { >> >>>> "Refund": { >> >>>> >> >>>> >> >>>> Regards, >> >>>> Anuj >> >>> >> >>> >> >> >> > >> > >
