Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to asynchronously service multiple QBWC clients with Node.js

The idea is to implement a QBWC web service using Node.js which can serve multiple incoming requests in an asynchronous fashion. Currently I am looking into qbws which is a Node.js web service for QuickBooks Desktop Web Connector. Any ideas on how I can extend this to support an asynchronous architecture for the service methods?
Thanks in Advance!

like image 649
newbie Avatar asked Sep 27 '22 14:09

newbie


People also ask

What are the different ways to deal with asynchronous code in NodeJS?

The asynchronous code will be written in three ways: callbacks, promises, and with the async / await keywords. Note: As of this writing, asynchronous programming is no longer done using only callbacks, but learning this obsolete method can provide great context as to why the JavaScript community now uses promises.

What is asynchronous operation in node JS?

Asynchronous programming in Node. js. Asynchronous I/O is a form of input/output processing that permits other processing to continue before the transmission has finished.

What does node JS contain in order to handle asynchronous events?

Node. js uses callbacks, being an asynchronous platform, it does not wait around like database query, file I/O to complete. The callback function is called at the completion of a given task; this prevents any blocking, and allows other code to be run in the meantime.


1 Answers

The soap module supports asynchronous function calls which makes this easy to do. To use the same template as my other answer, here's how you'd do that:

var soap = require('soap');

var yourService = {
    QBWebConnectorSvc: {
        QBWebConnectorSvcSoap: {
            serverVersion: function (args, callback) {

                // serverVersion code here

                callback({
                    serverVersionResult: { string: retVal }
                });
            },
            clientVersion: function (args, callback) {

                //clientVersion code here

                callback({
                    clientVersionResult: { string: retVal }
                });
            },

            // and all other service functions required by QBWC

        }
    }
};

There are two differences:

  1. Each method signature has an additional callback parameter
  2. There is no return, that's handled by callback() instead.

I don't currently have a suitable environment to test this, but I created a client to imitate QuickBooks Web Connector and it worked fine. Converting the qbws methods to asynchronous allowed it to service multiple clients simultaneously (including one legitimate QBWC client).

like image 123
JohnB Avatar answered Sep 30 '22 06:09

JohnB