SAP / node-rfc

Asynchronous, non-blocking SAP NW RFC SDK bindings for Node.js
Apache License 2.0
252 stars 73 forks source link

Dynamic Connection and Cache #318

Closed fortezhuo closed 8 months ago

fortezhuo commented 8 months ago

Is your feature request related to a problem? Please describe. Can I use node-rfc with dynamic configuration like dynamic DEST, SYSNR, ASHOST, etc ? And after create that dynamic connection, I can cache the connection for future use, And also set max dynamic connection and timer, if the max connection and the cache expired, the connection auto disconnect and we can reuse the slot for another different connection

Describe alternatives you've considered Is a good idea to store node-rfc connection on node-cache with timer ?

bsrdjan commented 8 months ago

It depends on scenario. After node-rfc Client connection is open, it remains open until closed by node-rfc Client close() (or nodejs script termination), or until closed by ABAP system, as per timeout configured there.

I did not test using node-cache but should work. Alternatively, you can try Connection Pool

Can I use node-rfc with dynamic configuration like dynamic DEST, SYSNR, ASHOST, etc ? Could you please describe what is meant with "dynamic configuration" ?

fortezhuo commented 8 months ago

Thanks for your quick reply.

The scenario : Since we have many platform (linux, mac m1, win) and node-rfc does not support alpine, so I want to create a tiny web app debian docker ready. The app (let named it "sap-webservice") will be installed nwrfcsdk, and provides service for sending data to SAP. So other apps (without have nwrfcsdk installed) just only send parameters like DEST, SYSNR, ASHOST, and data, etc to sap-webservice.

And the sap-webservice will do the job for connecting, open, and call RFC function based on parameters.

Since we have many RFC function with different configs, can we use connection pool like you suggested before ? I read the connection pool documentation, and it seems provide connection with same DEST only.

Or I should manage the multiple DEST connections manually using node-cache ? Can it caused memory leaks ?

bsrdjan commented 8 months ago

Instead of sending connection parameters over the network, using saplnwrfc.ini file on sap-webservice would be more secure alternative. The clients would then send only destination name, instead of all connection parameters. sap-webservice would then read from connection parameters from sapnwrfc.ini, no need for node-cache.

How the user logon data should be provided?

The connection pool works with only one dest, which does not help in your scenario, thus using Client is a better option.

fortezhuo commented 8 months ago

Thanks for your quick reply. For using Client is a better option, since sap-webservice will be hit by another apps for different dest, is a good idea for having multiple Client with different dest, and store the client into node-cache ? And user logon data for node-rfc authentication will be prompted and send over the network manually or we will using SSO for more secure alternative.

The question is for docker (node:lts-slim) what the path of SNC_LIB ? And can we use partially sapnwrfc.ini config with Client parameter ?

bsrdjan commented 8 months ago

Do client connections have to be open all the time? When the request with particular dest comes, the client connection can be opened and closed after RFC call(s) completed. Is cache really needed?

fortezhuo commented 8 months ago

I have tried, the cached client not working with node-cache. And the client connections have not to be opened all the time.. Is create new instance of node-rfc Client expensive ? if not expensive, I think I will ditch the cache..

bsrdjan commented 8 months ago

Expensive in terms of resources not and it is as fast as the network, thus should not be an issue. ABAP systems terminate idle RFC connections, per timeout configured there. The client connection can be therefore not open "forever".

node-rfc is open source but connection per RFC also requires ABAP user license, thus please also check RFC SDK icensing.

fortezhuo commented 8 months ago

Noted. Thanks for your quick reply. Issue closed