File tree Expand file tree Collapse file tree 3 files changed +21
-10
lines changed
Expand file tree Collapse file tree 3 files changed +21
-10
lines changed Original file line number Diff line number Diff line change @@ -14,18 +14,13 @@ export class AmqpModule {
1414 providers : [
1515 {
1616 provide : AmqpConnection ,
17- useFactory : ( ) => amqpClient . connect ( config ) ,
17+ useFactory : ( ) => AmqpService . createConnection ( config ) ,
1818 } ,
1919 {
2020 provide : AmqpChannel ,
2121 deps : [ AmqpConnection ] ,
22- useFactory : async ( connection : Connection ) => {
23- const channel = await connection . createChannel ( ) ;
24- if ( config . prefetchCount ) {
25- await channel . prefetch ( config . prefetchCount ) ;
26- }
27- return channel ;
28- } ,
22+ useFactory : async ( connection : Connection ) =>
23+ AmqpService . createChannel ( connection , config . prefetchCount ) ,
2924 } ,
3025 ] ,
3126 } ;
Original file line number Diff line number Diff line change 11import { Inject , Injectable } from '@rhtml/di' ;
22import { Channel , ConsumeMessage , Options } from 'amqplib' ;
3+ import amqpClient , { Connection } from 'amqplib' ;
34
4- import { AmqpChannel } from './amqp.constants' ;
5+ import { AmqpChannel , ModuleConfig } from './amqp.constants' ;
56
67@Injectable ( )
78export class AmqpService {
@@ -32,4 +33,19 @@ export class AmqpService {
3233 options ?. consumeOptions
3334 ) ;
3435 }
36+
37+ public static createConnection ( config : ModuleConfig ) {
38+ return amqpClient . connect ( config ) ;
39+ }
40+
41+ public static async createChannel (
42+ connection : Connection ,
43+ prefetchCount ?: number
44+ ) {
45+ const channel = await connection . createChannel ( ) ;
46+ if ( prefetchCount ) {
47+ await channel . prefetch ( prefetchCount ) ;
48+ }
49+ return channel ;
50+ }
3551}
Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ export const Subscribe =
2525 await target [ memberName ] . call ( this , msg , channel ) ;
2626 } catch ( e ) {
2727 console . error (
28- `[Subscription] : queue "${ queue } " fail internally inside ${ target } ${ memberName } `
28+ `[AMQP][Subscribe] : queue "${ queue } " failed to handle internally inside subscription " ${ memberName } " method `
2929 ) ;
3030 }
3131 } ,
You can’t perform that action at this time.
0 commit comments