@@ -663,6 +663,18 @@ export class WAStartupService {
663
663
} ;
664
664
}
665
665
666
+ private assertExchangeAsync = ( channel , exchangeName , exchangeType , options ) => {
667
+ return new Promise ( ( resolve , reject ) => {
668
+ channel . assertExchange ( exchangeName , exchangeType , options , ( error , ok ) => {
669
+ if ( error ) {
670
+ reject ( error ) ;
671
+ } else {
672
+ resolve ( ok ) ;
673
+ }
674
+ } ) ;
675
+ } ) ;
676
+ } ;
677
+
666
678
public async sendDataWebhook < T = any > ( event : Events , data : T , local = true ) {
667
679
const webhookGlobal = this . configService . get < Webhook > ( 'WEBHOOK' ) ;
668
680
const webhookLocal = this . localWebhook . events ;
@@ -687,22 +699,27 @@ export class WAStartupService {
687
699
if ( Array . isArray ( rabbitmqLocal ) && rabbitmqLocal . includes ( we ) ) {
688
700
const exchangeName = this . instanceName ?? 'evolution_exchange' ;
689
701
690
- amqp . assertExchange ( exchangeName , 'topic' , {
702
+ // await amqp.assertExchange(exchangeName, 'topic', {
703
+ // durable: true,
704
+ // autoDelete: false,
705
+ // });
706
+
707
+ await this . assertExchangeAsync ( amqp , exchangeName , 'topic' , {
691
708
durable : true ,
692
709
autoDelete : false ,
693
710
} ) ;
694
711
695
712
const queueName = `${ this . instanceName } .${ event } ` ;
696
713
697
- amqp . assertQueue ( queueName , {
714
+ await amqp . assertQueue ( queueName , {
698
715
durable : true ,
699
716
autoDelete : false ,
700
717
arguments : {
701
718
'x-queue-type' : 'quorum' ,
702
719
} ,
703
720
} ) ;
704
721
705
- amqp . bindQueue ( queueName , exchangeName , event ) ;
722
+ await amqp . bindQueue ( queueName , exchangeName , event ) ;
706
723
707
724
const message = {
708
725
event,
@@ -717,7 +734,7 @@ export class WAStartupService {
717
734
message [ 'apikey' ] = instanceApikey ;
718
735
}
719
736
720
- amqp . publish ( exchangeName , event , Buffer . from ( JSON . stringify ( message ) ) ) ;
737
+ await amqp . publish ( exchangeName , event , Buffer . from ( JSON . stringify ( message ) ) ) ;
721
738
722
739
if ( this . configService . get < Log > ( 'LOG' ) . LEVEL . includes ( 'WEBHOOKS' ) ) {
723
740
const logData = {
0 commit comments