SAP / node-rfc

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

Question: Direct & Pool connection #204

Closed ikit closed 3 years ago

ikit commented 3 years ago

Hi,

I'm using the node-rfc lib in an application that actually only use an unique applicative account. So I'm using the pool connections feature of the node-rfc v2. And all works fine.

Now I have to add a new feature that need to connect to SAP with the user account (user login and sso token). And I'm wondering what is the best way to implement it with node-rfc.

In the doc: I see that it's possible to use both direct and managed connection in my code.

But my application use express, and according to the doc it's not recommanded to use direct connection with it. Do I have to create a pool of connections for each connected user ? Does it means that I will have to create/delete user's connection pool each time I call my new feature ? is it ok ?

or should I use direct connection ?

bsrdjan commented 3 years ago

The pool connection parameters are user-dependent and one pool instance is required for each user.

Managed connections (pool) are not a must and direct connections can be used with express, see "Server" example in my latest blog: Generic ABAP Value Helps

The (express) application can only open direct connections, (client.open() method) and don't care about closing them. They will be implicitly closed, by server timeout or garbage collector. In this scenario no issues are expected with direct connections.

Once the application starts explicitly closing connections, by invoking client.close() from express for example, the concurrent access from express threads to the same connection object (handle), must be synchronised. As described in the documentation:

If not synchronised properly, the delayed direct client close() call, can close the handle already assigned to another client instance, typically causing the RFC_INVALID_HANDLE errors when that client tries to make the RFC call.

The Pool provides such synchronisation mechanism and applications can use it, if needed.

ikit commented 3 years ago

ok, thanks for the clarification :)