@@ -69,13 +69,13 @@ export class RabbitMQService implements OnModuleDestroy, OnApplicationShutdown {
69
69
}
70
70
}
71
71
72
- private connect ( queue : string , exchange : string , key : string ) {
72
+ private async connect ( queue : string , exchange : string , key : string ) {
73
73
try {
74
- this . channel . assertQueue ( queue , { durable : true } ) ;
75
- this . channel . assertExchange ( exchange , "topic" , {
74
+ await this . channel . assertQueue ( queue , { durable : true } ) ;
75
+ await this . channel . assertExchange ( exchange , "topic" , {
76
76
durable : true ,
77
77
} ) ;
78
- this . channel . bindQueue ( queue , exchange , key ) ;
78
+ await this . channel . bindQueue ( queue , exchange , key ) ;
79
79
} catch ( error ) {
80
80
throw new Error (
81
81
`Could not connect to RabbitMQ queue ${ queue } with exchange ${ exchange } and key ${ key } .` ,
@@ -84,10 +84,10 @@ export class RabbitMQService implements OnModuleDestroy, OnApplicationShutdown {
84
84
}
85
85
}
86
86
87
- sendMessage ( queue : string , exchange : string , key : string , message : string ) {
87
+ async sendMessage ( queue : string , exchange : string , key : string , message : string ) {
88
88
try {
89
- this . connect ( queue , exchange , key ) ;
90
- this . channel . sendToQueue ( queue , Buffer . from ( message ) , {
89
+ await this . connect ( queue , exchange , key ) ;
90
+ await this . channel . publish ( exchange , key , Buffer . from ( message ) , {
91
91
persistent : true ,
92
92
} ) ;
93
93
} catch ( error ) {
0 commit comments