@@ -8,23 +8,31 @@ interface Proxy {
8
8
[ state : string ] : any ;
9
9
}
10
10
11
+ type ConnectionOptions = Partial < {
12
+ keepAlive : number ;
13
+ lifetime : number ;
14
+ } >
15
+
11
16
export function createGatewayProxy (
12
17
url : string ,
13
18
definition : MicroserviceApi . ServiceDefinition ,
14
19
requestResponse ?: any ,
15
- requestStream ?: any
20
+ requestStream ?: any ,
21
+ options ?: ConnectionOptions
16
22
) : Promise < Proxy > ;
17
23
export function createGatewayProxy (
18
24
url : string ,
19
25
definition : MicroserviceApi . ServiceDefinition [ ] ,
20
26
requestResponse ?: any ,
21
- requestStream ?: any
27
+ requestStream ?: any ,
28
+ options ?: ConnectionOptions
22
29
) : Promise < Proxy [ ] > ;
23
30
export function createGatewayProxy (
24
31
url : string ,
25
32
definitions : any ,
26
33
customRequestResponse ?: any ,
27
- customRequestStream ?: any
34
+ customRequestStream ?: any ,
35
+ options ?: ConnectionOptions
28
36
) : any {
29
37
const isDefinitionsArray = Array . isArray ( definitions ) ;
30
38
let defs : MicroserviceApi . ServiceDefinition [ ] ;
@@ -36,7 +44,7 @@ export function createGatewayProxy(
36
44
const proxies : Proxy [ ] = [ ] ;
37
45
let socket ;
38
46
return new Promise ( async ( resolve , reject ) => {
39
- socket = await connect ( url ) . catch ( ( e ) => {
47
+ socket = await connect ( url , options ) . catch ( ( e ) => {
40
48
reject ( e ) ;
41
49
} ) ;
42
50
@@ -67,14 +75,14 @@ export function createGatewayProxy(
67
75
} ) ;
68
76
}
69
77
70
- const connect = ( url ) => {
78
+ const connect = ( url , options : ConnectionOptions = { } ) => {
71
79
return new Promise ( ( resolve , reject ) => {
72
80
const client = new RSocketClient ( {
73
81
serializers : JsonSerializers ,
74
82
setup : {
75
83
dataMimeType : 'application/json' ,
76
- keepAlive : 100000 ,
77
- lifetime : 100000 ,
84
+ keepAlive : options . keepAlive || 100000 ,
85
+ lifetime : options . lifetime || 100000 ,
78
86
metadataMimeType : 'application/json' ,
79
87
} ,
80
88
transport : new RSocketWebSocketClient ( { url } ) ,
0 commit comments