- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
Can I call javascript from MyProcesssor code in Apache Nifi?
- Labels:
-
Apache NiFi
Created ‎09-17-2016 02:57 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I want to call javascript script from MyProcessor code in Apache Nifi.
I am calling following binary parser written in javascript in java which is npm module .Can package.son and npm modules part of NAR
Code: Calling following
Javascript.js
var Parser = require('binary-parser').Parser;
// Build an IP packet header Parser
var ipHeader = new Parser()
.endianess('big')
.bit4('version')
.bit4('headerLength')
.uint8('tos')
.uint16('packetLength')
.uint16('id')
.bit3('offset')
.bit13('fragOffset')
.uint8('ttl')
.uint8('protocol')
.uint16('checksum')
.array('src', {
type: 'uint8',
length: 4
})
.array('dst', {
type: 'uint8',
length: 4
});
// Prepare buffer to parse.
var buf = new Buffer('450002c5939900002c06ef98adc24f6c850186d1', 'hex');
// Parse buffer and show result
console.log(ipHeader.parse(buf));
MyProcessor Code:
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("JavaScript");
if (!(engine instanceof Invocable)) {
System.out.println("Invoking methods is not supported.");
return;
}
Invocable inv = (Invocable) engine;
String scriptPath = "binaryParser.js";
Created ‎09-17-2016 04:17 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @Mohit Sharma,
You should look at the ExecuteScript and InvokeScriptedProcessor processors. Both of these processors can execute code written in Javascript directly from NiFi. @Matt Burgess has written very helpful blog posts on this functionality.
Created ‎09-17-2016 04:17 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @Mohit Sharma,
You should look at the ExecuteScript and InvokeScriptedProcessor processors. Both of these processors can execute code written in Javascript directly from NiFi. @Matt Burgess has written very helpful blog posts on this functionality.
Created ‎09-17-2016 11:11 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Andy for your response .I did try above mentioned options but have doubt regarding npm modules and package.json are not working in InvokeScriptedProcessor
Can you provide some implementation examples using javascript part from above mentioned links
Created ‎08-30-2017 06:03 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you want to include NPM modules, check this link for more details on how to use them with Nashorn.
Created ‎08-29-2017 02:57 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for your quick reply!
