How to create hyperledger fabric singleton gateway object using node js sdk?

197 Views Asked by At

We have a existing client application is made of fabric node js sdk to interact with blockchain network. It creates the gateway object and disconnect for every transaction. Can we reuse the gateway object somehow so that burden of creating and destroying gateway objet can be avoided.

Sdk version used : 2.2

Any help would be appreciated.

I have tried to make it singleton by creating the gateway object at the time of application start and make available throughout the application lifetime but sometime it's giving error like "timed out for discovery".

1

There are 1 best solutions below

0
On

The Gateway objects are designed to be reusable for multiple interactions using the same client identity, and this is recommended since tearing down and reestablishing gRPC connections when disposing of a Gateway object and creating a new one is expensive.

gRPC connections that are idle may get closed, particularly by firewalls or ingress controllers along the path between the Fabric client and network nodes. To avoid this causing issues, you may need to configure appropriate keep-alive settings for the Gateway connection. These references should help:

Note that a Gateway instance is tied to a single client identity so you will need multiple Gateway instances if your client application interacts with Fabric using multiple client identities.

The newer Fabric Gateway client API for Fabric v2.4 and later improves connection management by:

  1. requiring only a single gRPC connection from client application to a Gateway peer; and
  2. allowing multiple Gateway instances (each tied to a single client identity) to share a single gRPC connection.