@Mark Waterbury - I received your email and replied, but my exchange server seems to have difficulty in connecting to yours. The email is failing to be delivered. Anyway, here is the reply:



=================================================================
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



________________________________



NOTICE: The information in this electronic mail transmission is intended by CoralTree Systems Ltd for the use of the named individuals or entity to which it is directed and may contain information that is privileged or otherwise confidential. If you have received this electronic mail transmission in error, please delete it from your system without copying or forwarding it, and notify the sender of the error by reply email or by telephone, so that the sender's address records can be corrected.







--------------------------------------------------------------------------------





CoralTree Systems Limited

Company Registration Number 5021022.

Registered Office:

12-14 Carlton Place

Southampton

Hampshire

SO15 2EA

VAT Registration Number 834 1020 74.

--

This is the Web Enabling the IBM i (AS/400 and iSeries) (WEB400) mailing list To post a message email: WEB400@xxxxxxxxxxxx<mailto:WEB400@xxxxxxxxxxxx> To subscribe, unsubscribe, or change list options,

visit: http://lists.midrange.com/mailman/listinfo/web400

or email: WEB400-request@xxxxxxxxxxxx<mailto:WEB400-request@xxxxxxxxxxxx>

Before posting, please take a moment to review the archives at http://archive.midrange.com/web400.





___________________________________________

This email has been scanned by iomartcloud.

http://www.iomartcloud.com/



________________________________

NOTICE: The information in this electronic mail transmission is intended by CoralTree Systems Ltd for the use of the named individuals or entity to which it is directed and may contain information that is privileged or otherwise confidential. If you have received this electronic mail transmission in error, please delete it from your system without copying or forwarding it, and notify the sender of the error by reply email or by telephone, so that the sender's address records can be corrected.



--------------------------------------------------------------------------------


CoralTree Systems Limited
Company Registration Number 5021022.
Registered Office:
12-14 Carlton Place
Southampton
Hampshire
SO15 2EA
VAT Registration Number 834 1020 74.

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.