我有像这样的groovy代码,我想提取TickSolution的值,然后用它作为调用服务的参数,我应该使用哪些nifi处理器来完成这项任务?
import java.nio.charset.StandardCharsets
import org.apache.commons.io.IOUtils
import org.apache.nifi.processor.io.StreamCallback
import java.text.SimpleDateFormat
import java.util.GregorianCalendar
def flowfile = session.get()
if(!flowfile) return
def date=flowfile.getAttribute('fromDate')
SimpleDateFormat format=new SimpleDateFormat("yyyy-mm-dd");
def d=new Date(format.parse(date).getTime());
def newdate=new GregorianCalendar(d.getYear(),d.getMonth(),d.getDay() )
def TICKS_AT_EPOCH = 621355968000000000;
def TICKS_PER_MILLISECOND= 10000;
def TickSolution=(newdate.getTimeInMillis() - TICKS_AT_EPOCH) / TICKS_PER_MILLISECOND
flowfile = session.putAttribute(flowfile, 'filename','Info'+'_'+date)
session.transfer(flowfile, REL_SUCCESS)
答案 0 :(得分:1)
萨利,
您可以尝试以下代码来处理TickSolution的值。
import java.nio.charset.StandardCharsets
import org.apache.commons.io.IOUtils
import org.apache.nifi.processor.io.StreamCallback
import java.text.SimpleDateFormat
import java.util.GregorianCalendar
def flowfile = session.get()
if(!flowfile) return
def date=flowfile.getAttribute('fromDate')
SimpleDateFormat format=new SimpleDateFormat("yyyy-mm-dd");
def d=new Date(format.parse(date).getTime());
def newdate=new GregorianCalendar(d.getYear(),d.getMonth(),d.getDay() )
def TICKS_AT_EPOCH = 621355968000000000;
def TICKS_PER_MILLISECOND= 10000;
def TickSolution=(newdate.getTimeInMillis() - TICKS_AT_EPOCH) / TICKS_PER_MILLISECOND
flowfile = session.putAttribute(flowfile, 'filename','Info'+'_'+date)
flowfile=session.putAttribute(flowfile,'TickSolution',TickSolution)
session.transfer(flowfile, REL_SUCCESS)
如果您遇到任何问题,请告诉我。