Search code examples
apache-nifi

I want to store all json data in flowfile attribute in apache nifi


Here is a scenario where I've data in flowfile in json format which is splited using split json and I want to store all the data of single row in the flowfile attribute. I'm trying to use updateattribute processor where through sources I came to know that we can use '${file:toBase64()}' expression to a variable to store all data in base 64 format to the variable and that variable will be added to flowfile attribute having all data.

Here after using '${file:toBase64()}' I'm getting error that it is not a valid expression. Please help me that why it is showing error and if do not have any idea regarding this then provide me a solution where I can store all the key values pairs of json data somewhere so that I can retrieve it later after some processor execution is done. *The data will vary so evaluatejsonpath or updateattribute will not work.

Error picture


Solution

  • You should avoid parsing content to attributes as that is a NiFi Best Practices Anti-Pattern. If you want to build a dataflow to process key/value pairs and store them later you should take a look at Distributed Map Cache and internal nifi data store. You can also use an external data store like hbase, cassandra, or redis amongst others. You will find a Put and Fetch Processor, a Controller Services Client and Server. Docs Below.

    References:

    https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-distributed-cache-services-nar/1.20.0/org.apache.nifi.distributed.cache.client.DistributedMapCacheClientService/index.html

    https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-distributed-cache-services-nar/1.20.0/org.apache.nifi.distributed.cache.server.map.DistributedMapCacheServer/index.html

    https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.20.0/org.apache.nifi.processors.standard.PutDistributedMapCache/index.html

    https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.20.0/org.apache.nifi.processors.standard.FetchDistributedMapCache/index.html