This folder includes example cloud code that demonstrates how to add PL/SQL and Advanced Queueing as APIS for Mobile and Web Developers. This demo code is configured to run against Free23c. There is 1 new file
- qapi.js - a collection of cloud functions for supporting common queueing functions. These cloud fucntions are written using the Node.js Oracle module.
Copy the cloud dir to the project root
cp -R src/Adapters/Storage/Oracle/cloud .
Add cloud code location to config.json
"cloud": "./cloud/qapi.js",
And boot the server
ORACLE_CLIENT_LOCATION=/Users/myuser/instantclient_19_8 npm start -- ./config.json
-
Create Queue
Input Parameter
qname - name of queue
curl -X POST -H "X-Parse-Application-Id: APPLICATION_ID" -H "Content-Type: application/json" -d '{ "qname": "FRED"}' http://localhost:1338/parse/functions/createQ
-
Enqueue Message
Input Parameter
qname - name of queue to enqueu message
msg - message to enque
curl -X POST -H "X-Parse-Application-Id: APPLICATION_ID" -H "Content-Type: application/json" -d '{"qname": "FRED","msg": "Wilma says Hi"}' http://localhost:1338/parse/functions/enqueMsg
-
Dequeue Message
Input Parameter
qname - name of queue to dequeue message
curl -X POST -H "X-Parse-Application-Id: APPLICATION_ID" -H "Content-Type: application/json" -d '{"qname": "FRED"}' http://localhost:1338/parse/functions/dequeMsg
NOTE: The API will block if there are no messages to dequeue
Continuous Query Notification is used to get around this limitation. The message is then pushed to the mobile device using Parse Server's Push Notification suopprt. Look at the setCQN cloud code function which registers a callback.
There are a series of Linked In posts that describe this in detail
- Building a Custom MBaaS Server with Oracle's MERN Stack
- Using Oracle's Continuous Query Notifications in a Mobile App
- Push Notifications with Oracle's MERN Stack
qapi.js embeds the credentials that are used to get an active conection. A better option would be to use the server's internal connection pool. Added to the cloud dir are;
connection.js - methods that get connections from the server pool qapisrvrpool.js - cloud code functions that now use connection.js to obtain connections from the server pool
To use the server pool, 3 modifications are required for OracleStorageAdapter.js
-
import setter from connection.js
import { setOracleStorageAdapter } from '../../../../cloud/connection';
this assumes that cloud directory is subordinate to project root
-
call setOracleStorageAdapter in connection.js during construction of Storage Adapter
this._uri = options.databaseURI; this._collectionPrefix = options.collectionPrefix; this._connectionPool = null; this._collections = new Map(); setOracleStorageAdapter(this);
-
Enable events for connections in the pool. In the connect method add events: true
this.connectionPromise = await oracledb.createPool({ poolAlias: 'parse', user: user, password: pw, connectString: tnsname, poolIncrement: 5, poolMax: 100, poolMin: 3, poolTimeout: 10, enableStatistics: true, events: true,
Rebuild the server
npm cache clean --force
npm ci
Add cloud code location to config.json
"cloud": "./cloud/qapisrvrpool.js",
And boot the server
ORACLE_CLIENT_LOCATION=/Users/myuser/instantclient_19_8 npm start -- ./config.json