@@ -17,6 +17,7 @@ import {
17
17
RQM_DEFAULT_QUEUE ,
18
18
RQM_DEFAULT_QUEUE_OPTIONS ,
19
19
RQM_DEFAULT_URL ,
20
+ RQM_NO_EVENT_HANDLER ,
20
21
} from '../constants' ;
21
22
import { RmqContext } from '../ctx-host' ;
22
23
import { Transport } from '../enums' ;
@@ -25,6 +26,7 @@ import { CustomTransportStrategy, RmqOptions } from '../interfaces';
25
26
import {
26
27
IncomingRequest ,
27
28
OutgoingResponse ,
29
+ ReadPacket ,
28
30
} from '../interfaces/packet.interface' ;
29
31
import { RmqRecordSerializer } from '../serializers/rmq-record.serializer' ;
30
32
import { Server } from './server' ;
@@ -42,6 +44,7 @@ export class ServerRMQ extends Server implements CustomTransportStrategy {
42
44
protected readonly urls : string [ ] | RmqUrl [ ] ;
43
45
protected readonly queue : string ;
44
46
protected readonly prefetchCount : number ;
47
+ protected readonly noAck : boolean ;
45
48
protected readonly queueOptions : any ;
46
49
protected readonly isGlobalPrefetchCount : boolean ;
47
50
protected readonly noAssert : boolean ;
@@ -54,6 +57,7 @@ export class ServerRMQ extends Server implements CustomTransportStrategy {
54
57
this . prefetchCount =
55
58
this . getOptionsProp ( this . options , 'prefetchCount' ) ||
56
59
RQM_DEFAULT_PREFETCH_COUNT ;
60
+ this . noAck = this . getOptionsProp ( this . options , 'noAck' , RQM_DEFAULT_NOACK ) ;
57
61
this . isGlobalPrefetchCount =
58
62
this . getOptionsProp ( this . options , 'isGlobalPrefetchCount' ) ||
59
63
RQM_DEFAULT_IS_GLOBAL_PREFETCH_COUNT ;
@@ -141,8 +145,6 @@ export class ServerRMQ extends Server implements CustomTransportStrategy {
141
145
}
142
146
143
147
public async setupChannel ( channel : any , callback : Function ) {
144
- const noAck = this . getOptionsProp ( this . options , 'noAck' , RQM_DEFAULT_NOACK ) ;
145
-
146
148
if ( ! this . queueOptions . noAssert ) {
147
149
await channel . assertQueue ( this . queue , this . queueOptions ) ;
148
150
}
@@ -151,7 +153,7 @@ export class ServerRMQ extends Server implements CustomTransportStrategy {
151
153
this . queue ,
152
154
( msg : Record < string , any > ) => this . handleMessage ( msg , channel ) ,
153
155
{
154
- noAck,
156
+ noAck : this . noAck ,
155
157
} ,
156
158
) ;
157
159
callback ( ) ;
@@ -200,6 +202,19 @@ export class ServerRMQ extends Server implements CustomTransportStrategy {
200
202
response$ && this . send ( response$ , publish ) ;
201
203
}
202
204
205
+ public async handleEvent (
206
+ pattern : string ,
207
+ packet : ReadPacket ,
208
+ context : RmqContext ,
209
+ ) : Promise < any > {
210
+ const handler = this . getHandlerByPattern ( pattern ) ;
211
+ if ( ! handler && ! this . noAck ) {
212
+ this . channel . nack ( context . getMessage ( ) , false , false ) ;
213
+ return this . logger . warn ( RQM_NO_EVENT_HANDLER `${ pattern } ` ) ;
214
+ }
215
+ return super . handleEvent ( pattern , packet , context ) ;
216
+ }
217
+
203
218
public sendMessage < T = any > (
204
219
message : T ,
205
220
replyTo : any ,
0 commit comments