-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnosql.ts
41 lines (33 loc) · 1.31 KB
/
nosql.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const { GRPC_NOSQL_SERVER_HOST, GRPC_NOSQL_SERVER_PORT } = process.env;
import "source-map-support/register";
import { credentials, Metadata } from "@grpc/grpc-js";
import { promisify } from "util";
import { PartiQLQueryClient, QueryRequest, QueryResponse } from "../models/nosql/parti_ql";
class NoSQLClient {
// https://github.com/grpc/grpc/blob/master/doc/keepalive.md
// https://cloud.ibm.com/docs/blockchain-multicloud?topic=blockchain-multicloud-best-practices-app#best-practices-app-connections
private readonly client: PartiQLQueryClient = new PartiQLQueryClient(
`${GRPC_NOSQL_SERVER_HOST}:${GRPC_NOSQL_SERVER_PORT}`, // 5051
credentials.createInsecure(),
{
"grpc.keepalive_time_ms": 120000,
"grpc.http2.min_time_between_pings_ms": 120000,
"grpc.keepalive_timeout_ms": 20000,
"grpc.http2.max_pings_without_data": 0,
"grpc.keepalive_permit_without_calls": 1,
}
);
constructor() {
console.log(`NoSQLClient: ${GRPC_NOSQL_SERVER_HOST}:${GRPC_NOSQL_SERVER_PORT}`);
}
public async query(
param: QueryRequest,
metadata: Metadata = new Metadata()
): Promise<QueryResponse> {
return promisify<QueryRequest, Metadata, QueryResponse>(this.client.query.bind(this.client))(
param,
metadata
);
}
}
export const noSqlClient = new NoSQLClient();