All,
I am new to the scripted record environment but have done Groovy scripts
with ExecuteScript and other customizations with the interface... So not a
power user but maybe mid-tier.
I am trying to create a ScriptedRecordSetWriter that accesses a controller
service (map cache). We need to do a lookup for each record and doing it in
broken out flow files won't scale.
I can do this in an ExecuteScript with something like this:
-----------------
import org.apache.nifi.distributed.cache.client.DistributedMapCacheClient
import org.apache.nifi.distributed.cache.client.Serializer
import org.apache.nifi.distributed.cache.client.Deserializer
import java.nio.charset.StandardCharsets
def ff = session.get()
if(!ff) return
def StringSerializer = {value, out ->
out.write(value.getBytes(StandardCharsets.UTF_8))} as Serializer<String>
def StringDeserializer = { bytes -> new String(bytes) } as
Deserializer<String>
def myDistClient =
AggMapClientService.*asControllerService*(DistributedMapCacheClient)
mn = ff.getAttribute('record.mn')
def result = myDistClient.get(mn, StringSerializer, StringDeserializer)
log.info("Result = $result")
session.transfer(ff, REL_SUCCESS)
------------------
But this only works because I am passing the UUID of the controller service
as a property. This shows up in the script as a type PropertyValue and
"asControllerService" becomes possible.
What I can't find is any example of how to access properties in the
ScriptedRecordSetWriter. And it may be that I can't access controller
services in the script for this service.
Any pointers/examples would be greatly appreciated. If someone has tried to
access a controller service from a ScriptedRecordSetWriter and determined it
is not possible, I would appreciate that knowledge as well!
Thanks in advance
Dave
--
Sent from: http://apache-nifi-users-list.2361937.n4.nabble.com/