Nifi executeScript不起作用

时间:2018-08-08 16:53:48

标签: javascript apache-nifi

我正在尝试运行ExecuteScript,该脚本应该接收json消息并解析字段以进行进一步处理,但是我无法使它正常工作。我为该作者创建的ExecuteScript运行了一个测试器:

https://funnifi.blogspot.com/2016/06/testing-executescript-processor-scripts.html

它返回以下错误:

无法从抽象接口org.apache.nifi.processor.io.StreamCallback

创建实例

我在脚本中看不到错误,因此有人可以协助解决此问题:

flowFile = session.get();
if (flowFile != null) {
    var StreamCallback = Java.type("org.apache.nifi.processor.io.StreamCallback");
    var IOUtils = Java.type("org.apache.commons.io.IOUtils");
    var StandardCharsets = Java.type("java.nio.charset.StandardCharsets");
    var transformed_message = {};
    var error = false;
    var line = "ops_track";
    // Get attributes
    flowFile = session.write(flowFile, new StreamCallback(function (inputStream,
                                                                    outputStream) {
        // Read input FlowFile content
        var content = IOUtils.toString(inputStream, StandardCharsets.UTF_8); // message or content
        var message_content = {};
        try {
            message_content = JSON.parse(content);
            transformed_message.postID = (((message_content || {}).postID || "null"));
            transformed_message.contentType = (((message_content || {}).contentType || "null"));

            transformed_message.published =
                (((message_content || {}).published || "null"));
            transformed_message.crawled = (((message_content || {}).crawled || "null"));
            transformed_message.providerID = (((message_content || {}).providerID || "null"));

            line = line + " " + "postID=" + transformed_message.postID + ","
                + "contentType=" + transformed_message.contentType + ","
                + "published=" + transformed_message.published + ","
                + "crawled=" + transformed_message.crawled + ","
                + "providerID=" + transformed_message.providerID + ","
                + "value=" + "1" + " "
                + time * 1000000 + "\n";

            // Write output content
            if (transformed_message) {
                outputStream.write(line.getBytes(StandardCharsets.UTF_8));
            }
        } catch (e) {
            error = true;
            outputStream.write(content.getBytes(StandardCharsets.UTF_8));
        }
    }));


    if (error) {
        session.transfer(flowFile, REL_FAILURE)
    } else {
        session.transfer(flowFile, REL_SUCCESS)
    }
}

0 个答案:

没有答案