@@ -65,8 +65,9 @@ export abstract class IMQClient extends EventEmitter {
65
65
public readonly queueName : string ;
66
66
67
67
private readonly baseName : string ;
68
- private imq : IMessageQueue ;
69
- private static singleImq : IMessageQueue ;
68
+ private readonly imq : IMessageQueue ;
69
+ private readonly subscriptionImq : IMessageQueue ;
70
+ private static singleImq : IMessageQueue & { name ?: string } ;
70
71
private readonly logger : ILogger ;
71
72
private resolvers : { [ id : string ] : [
72
73
( data : AnyJson , res : IMQRPCResponse ) => void ,
@@ -101,11 +102,13 @@ export abstract class IMQClient extends EventEmitter {
101
102
this . options = { ...DEFAULT_IMQ_CLIENT_OPTIONS , ...options } ;
102
103
this . id = pid ( baseName ) ;
103
104
this . logger = this . options . logger || /* istanbul ignore next */ console ;
104
- this . hostName = `${ osUuid ( ) } -${ this . id } :client` ;
105
+ this . hostName = IMQClient . singleImq ?. name ||
106
+ `${ osUuid ( ) } -${ this . id } :client` ;
105
107
this . name = `${ baseName } -${ this . hostName } ` ;
106
108
this . serviceName = serviceName || baseName . replace ( / C l i e n t $ / , '' ) ;
107
109
this . queueName = this . options . singleQueue ? this . hostName : this . name ;
108
110
this . imq = this . createImq ( ) ;
111
+ this . subscriptionImq = this . createSubscriptionImq ( ) ;
109
112
110
113
SIGNALS . forEach ( ( signal : any ) => process . on ( signal , async ( ) => {
111
114
this . destroy ( ) . catch ( this . logger . error ) ;
@@ -126,6 +129,14 @@ export abstract class IMQClient extends EventEmitter {
126
129
return IMQClient . singleImq ;
127
130
}
128
131
132
+ private createSubscriptionImq ( ) : IMessageQueue {
133
+ if ( ! this . options . singleQueue ) {
134
+ return this . imq ;
135
+ }
136
+
137
+ return IMQ . create ( this . name , this . options ) ;
138
+ }
139
+
129
140
/**
130
141
* Sends call to remote service method
131
142
*
@@ -200,7 +211,7 @@ export abstract class IMQClient extends EventEmitter {
200
211
* @return {Promise<void> }
201
212
*/
202
213
public async subscribe ( handler : ( data : JsonObject ) => any ) : Promise < void > {
203
- return this . imq . subscribe ( this . queueName , handler ) ;
214
+ return this . subscriptionImq . subscribe ( this . name , handler ) ;
204
215
}
205
216
206
217
// noinspection JSUnusedGlobalSymbols
@@ -210,7 +221,7 @@ export abstract class IMQClient extends EventEmitter {
210
221
* @return {Promise<void> }
211
222
*/
212
223
public async unsubscribe ( ) : Promise < void > {
213
- return this . imq . unsubscribe ( ) ;
224
+ return this . subscriptionImq . unsubscribe ( ) ;
214
225
}
215
226
216
227
// noinspection JSUnusedGlobalSymbols
@@ -257,7 +268,9 @@ export abstract class IMQClient extends EventEmitter {
257
268
resolve && resolve ( message . data , message ) ;
258
269
} ) ;
259
270
260
- await this . imq . start ( ) ;
271
+ if ( this . imq ) {
272
+ await this . imq . start ( ) ;
273
+ }
261
274
}
262
275
263
276
// noinspection JSUnusedGlobalSymbols
0 commit comments