@@ -118,8 +118,11 @@ export class SqsController extends EventController implements EventControllerInt
118118 }
119119
120120 if ( Array . isArray ( sqsEvents ) && sqsEvents . includes ( we ) ) {
121- const eventFormatted = `${ event . replace ( '.' , '_' ) . toLowerCase ( ) } ` ;
122121 const prefixName = sqsConfig . GLOBAL_ENABLED ? sqsConfig . GLOBAL_PREFIX_NAME : instanceName ;
122+ const eventFormatted =
123+ sqsConfig . GLOBAL_ENABLED && sqsConfig . GLOBAL_FORCE_SINGLE_QUEUE
124+ ? 'singlequeue'
125+ : `${ event . replace ( '.' , '_' ) . toLowerCase ( ) } ` ;
123126 const queueName = `${ prefixName } _${ eventFormatted } .fifo` ;
124127
125128 const sqsUrl = `https://sqs.${ sqsConfig . REGION } .amazonaws.com/${ sqsConfig . ACCOUNT_ID } /${ queueName } ` ;
@@ -199,20 +202,23 @@ export class SqsController extends EventController implements EventControllerInt
199202
200203 private async saveQueues ( prefixName : string , events : string [ ] , enable : boolean ) {
201204 if ( enable ) {
205+ const sqsConfig = configService . get < Sqs > ( 'SQS' ) ;
202206 const eventsFinded = await this . listQueues ( prefixName ) ;
203207 console . log ( 'eventsFinded' , eventsFinded ) ;
204208
205209 for ( const event of events ) {
206- const normalizedEvent = event . toLowerCase ( ) ;
207-
210+ const normalizedEvent =
211+ sqsConfig . GLOBAL_ENABLED && sqsConfig . GLOBAL_FORCE_SINGLE_QUEUE
212+ ? 'singlequeue'
213+ : event . toLowerCase ( ) ;
208214 if ( eventsFinded . includes ( normalizedEvent ) ) {
209215 this . logger . info ( `A queue para o evento "${ normalizedEvent } " já existe. Ignorando criação.` ) ;
210216 continue ;
211217 }
212218
213219 const queueName = `${ prefixName } _${ normalizedEvent } .fifo` ;
214220 try {
215- const isGlobalEnabled = configService . get < Sqs > ( 'SQS' ) . GLOBAL_ENABLED ;
221+ const isGlobalEnabled = sqsConfig . GLOBAL_ENABLED ;
216222 const createCommand = new CreateQueueCommand ( {
217223 QueueName : queueName ,
218224 Attributes : {
@@ -226,6 +232,10 @@ export class SqsController extends EventController implements EventControllerInt
226232 } catch ( err : any ) {
227233 this . logger . error ( `Erro ao criar queue ${ queueName } : ${ err . message } ` ) ;
228234 }
235+
236+ if ( sqsConfig . GLOBAL_ENABLED && sqsConfig . GLOBAL_FORCE_SINGLE_QUEUE ) {
237+ break ;
238+ }
229239 }
230240 }
231241 }
0 commit comments