Kevin:

Looking at the code you posted (below), it appears that you are trying to invoke QRCVDTAQ with only eight (8) parameters. According to the API documentation, QRCVDTAQ requires five (5) parameters for the "normal" non-keyed case, or ten (10) parameters for the "keyed" data queue case, or thirteen (13) parameters, if you want to specify "*NO" for "remove message" or if you want to specify the "size of data receiver" or to provide the standard API error code data structure to detect any errors. (If the error code data structure is not provided, the API will throw *ESCAPE messages if errors are detected.)

So, you appear to be "missing" the "sender length" and "sender data" parameters. If you do not want the "sender information", you must still pass those parameters, and pass a value of "zero" for "sender length."

Hope that helps,

Mark S. Waterbury

> On 8/23/2015 7:04 AM, Kevin Turner wrote:
...(snip)...
=================================================================
Here is the code in my little worker.js child process. I am hoping I have just made a mistake somewhere, but the error response is not telling me much. I tried debugging the XMLSERVICE code but it seems that the source is out of sequence with the executable. I just kept stepping into comments etc :)

// This tiny node app will wait for an entry on a queue and pass it to the process that spawned (forked) it

var dq = require('/QOpenSys/QIBM/ProdData/Node/os400/xstoolkit/lib/idataq');
var xt = require('/QOpenSys/QIBM/ProdData/Node/os400/xstoolkit/lib/itoolkit');
var DBname = "*LOCAL ";

//Add a new function for keyed data queues
dq.iDataQueue.prototype.receiveFromKeyedDataQueue = function(name, lib, length, wait, keyOp, keyLen, key, cb) {
// TODO Replace QRCVDTAQ with a call to an RPGLE program that will do the job
var pgm = new xt.iPgm("QRCVDTAQ", {"lib":"QSYS"});
pgm.addParam(name, "10A");
pgm.addParam(lib == ""?"*CURLIB":lib, "10A");
pgm.addParam(length, "5p0");
pgm.addParam("", length + 1 + "A");
pgm.addParam(wait, "5p0");
pgm.addParam(keyOp, "2A");
pgm.addParam(keyLen, "3p0");
pgm.addParam(key, key.length + "A")

this.conn.add(pgm.toXML());
var async = cb && xt.getClass(cb) == "Function"; //If there is a callback function param, then it is in asynchronized mode.
var rtValue; // The returned value.
var stop = 0; // A flag indicating whether the process is finished.
var retry = 0; // How many times we have retried.
function toJson(str) { // Convert the XML output into JSON
var output = xt.xmlToJson(str);
if(output[0].success)
rtValue = output[0].data[3].value;
else
rtValue = str;
if(async) // If it is in asynchronized mode.
cb(rtValue); // Run the call back function against the returned value.
stop = 1;
}
function waitForResult() {
retry++;
if(stop == 0)
setTimeout('waitForResult()', retryInterval); // Check whether the result is retrieved
else if(retry >= retryTimes)
return timeoutMsg;
else
return rtValue;
}
this.conn.run(toJson); // Post the input XML and get the response.
if(!async) // If it is in synchronized mode.
return waitForResult(); // Run the user defined call back function against the returned value.
}

// When we get some data, start listening to the queue
process.on('message', function(dqObj) {
// Wait for stuff to arrive on a data queue also
var conn = new xt.iConn(DBname);
var dtaq = new dq.iDataQueue(conn);
var dtaqN = dqObj.name;
var lib = dqObj.lib;


function cb(str) {
if (str) {
// Pass results back to parent process
process.send(str);
}
// Wait again
dtaq.receiveFromKeyedDataQueue(dtaqN, lib, 64512, 1, 'EQ', 6, 'THEKEY', cb);
}

// Wait for something to arrive on the queue, timing out every 1 second to allow
// us to check other stuff
dtaq.receiveFromKeyedDataQueue(dtaqN, lib, 64512, 1, 'EQ', 6, 'THEKEY', cb);

});







-----Original Message-----
From: WEB400 [mailto:web400-bounces@xxxxxxxxxxxx] On Behalf Of Kevin Turner
Sent: 22 August 2015 20:11
To: Web Enabling the IBM i (AS/400 and iSeries)
Subject: [WEB400] Who knows all about XMLSERVICE?

A bit of background:

I am trying to access a keyed data queue from a node.js function using the IBM toolkit provided. Not entirely unexpectedly, the documentation with the toolkit is pretty sparse on examples https://www.ibm.com/developerworks/ibmi/library/i-native-js-app-ibmi-with-nodejs/

They provide a script called "idataq.js" that shows examples of sending and receiving data to a non-keyed data queue. It appears to use XMLSERVICE under the covers to do so, and it works as far as my testing goes. However, that is no good if you want to access a keyed data queue.

I figured I would just create a modified version of the supplied "receiveFromDataQueue" function to include the extra parameters needed for a keyed data queue, but it fails miserably. The XML error response from XMLSERVICE is virtually useless, but I have managed to glean the fact that it expects only 5 parameters, not the 8 I want to send it. Does anyone know how to make the error responses more meaningful?

The code appears to just create an XML interface to the QRCVDTAQ program, so why would it complain about only wanting 5 parameters unless it is some sort of hardcoded limit for the API built in to XMLSERVICE somewhere? Does anyone know if this is the case. The basic code for the version that works looks like this:

var xt = require('./itoolkit');

var pgm = new xt.iPgm("QRCVDTAQ", {"lib":"QSYS"}); pgm.addParam(name, "10A"); pgm.addParam(lib == ""?"*CURLIB":lib, "10A"); pgm.addParam(length, "5p0"); pgm.addParam("", length + 1 + "A"); pgm.addParam(0, "5p0");this.conn.add(pgm.toXML());

this.conn.run(toJson);

but calling QSNDDTAQ like this does not work var xt = require('./itoolkit'); var pgm = new xt.iPgm("QRCVDTAQ", {"lib":"QSYS"}); pgm.addParam(name, "10A"); pgm.addParam(lib == ""?"*CURLIB":lib, "10A"); pgm.addParam(length, "5p0"); pgm.addParam("", length + 1 + "A"); pgm.addParam(5, "5p0");this.conn.add(pgm.toXML());

pgm.addParam(keyOp, "2A");

pgm.addParam(keyLen, "3p0");

pgm.addParam(key, key.length + "A")

this.conn.run(toJson);

I thought I would try to write my own program to see if that would work (rather than using QRCVDTAQ directly) but I cannot find any examples of what my program signature should look like. I have looked at the documentation for XMLTOOLKIT for examples but (IMHO) the documentation is pretty dreadful.....not an uncommon complaint for IBM stuff.

Just a simple RPG example program would be useful.

Thanks

...(snip)...


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.