Forum Discussion
Satoshi_Toyosa1
Employee
iRules LX comes with two flavour. One is RPC style as above. It uses both iRules (TCL) and node. The other one is Streaming. It's pure Node without TCL, which became available from v13.0.
Here's a Streaming example. The specification is same as the RPC one.
var f5 = require('f5-nodejs');
var plugin = new f5.ILXPlugin();
// string to json parser (same as RPC version)
var parser = function(str) {
var json = {"error":"unable to parse"};
try {
json = JSON.parse(str);
}
catch(e) {
console.log('Got non-Json data: ' + e + ' >>> ' + str);
}
return json;
}
// Reading buffer and return string
var readMe = function(ilxTransaction) {
var chunk = [];
while(true) {
var buffer = ilxTransaction.read();
if (buffer !== null) {
chunk.push(buffer);
}
else {
break;
}
}
return chunk.join('').toString() || '{"error":"no data"}';
}
// Main loop
plugin.on('connect', function(flow) {
// Started to receive client POST data
var postData = '';
flow.client.on('readable', function(req) {
postData = readMe(flow.client);
});
// Got all the client POST data. Send it over to poolMember
flow.client.on('requestComplete', function(req) {
console.log('client req (POST): ' + postData);
var postDataJson = parser(postData);
postDataJson['newKey'] = 'new';
console.log('req to poolmember: ' + JSON.stringify(postDataJson));
flow.server.write(JSON.stringify(postDataJson));
req.complete();
console.log('res done');
});
// Started to receive poolMember body
var body = '';
flow.server.on('readable', function(res) {
body = readMe(flow.server);
});
// Got all the server data. Push it to client
flow.server.on('responseComplete', function(res) {
console.log('server res (body): ' + body);
var bodyJson = parser(body);
delete bodyJson['aoc'];
console.log('res to client: ' + JSON.stringify(bodyJson));
flow.client.write(JSON.stringify(bodyJson));
res.complete();
});
// Error notification
flow.client.on('error', function(errorText) {
console.log("client error event: " + errorText);
});
flow.server.on('error', function(errorText) {
console.log("server error event: " + errorText);
});
flow.on("error", function(errorText) {
console.log("flow error event: " + errorText);
});
});
var options = new f5.ILXPluginOptions();
// No specific option here
plugin.start(options);
DanSchell
May 24, 2019Nimbostratus
Hi Satoshi,
that means the pure stream example does not need the iRule part, only the XL Workspace js extension?
- Satoshi_Toyosa1May 29, 2019Employee
Yes, iRules LX Streaming does not require iRules. Instead, you create the profile from the plugin, and attach it to the virtual.