Skip to content

Commit

Permalink
fix(rabbitmq): fix library asserting queues with empty names
Browse files Browse the repository at this point in the history
This is an attempt to fix the issue where this library doesn't pass the right arguments to
setupQueue in setupQueuesWithBindings. In addition, this removes the duplicate setup that
setupQueuesWithBindings was doing that setupQueue alredy does.

re golevelup#671
  • Loading branch information
ttshivers committed Jan 15, 2024
1 parent 1891b32 commit 288c4b8
Showing 1 changed file with 16 additions and 32 deletions.
48 changes: 16 additions & 32 deletions packages/rabbitmq/src/amqp/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,36 +296,20 @@ export class AmqpConnection {
queues: RabbitMQQueueConfig[]
) {
for (const configuredQueue of queues) {
const { createQueueIfNotExists = true } = configuredQueue;

if (createQueueIfNotExists) {
this.setupQueue(configuredQueue, channel);
}
await channel.assertQueue(configuredQueue.name, configuredQueue.options);

let routingKeys: string[] = [];
if (Array.isArray(configuredQueue.routingKey)) {
routingKeys = configuredQueue.routingKey;
} else {
if (configuredQueue.routingKey != null) {
routingKeys = [configuredQueue.routingKey];
}
}

if (routingKeys.length > 0) {
await Promise.all(
routingKeys.map((routingKey) => {
if (configuredQueue.exchange != undefined) {
channel.bindQueue(
configuredQueue.name,
configuredQueue.exchange,
routingKey,
configuredQueue.bindQueueArguments
);
}
})
);
}
const { name, options, bindQueueArguments, ...rest } = configuredQueue;
const queueOptions = {
...options,
...(bindQueueArguments !== undefined && { bindQueueArguments }),
};

await this.setupQueue(
{
...rest,
...(name !== undefined && { queue: name }),
queueOptions,
},
channel
);
}
}

Expand Down Expand Up @@ -693,8 +677,8 @@ export class AmqpConnection {
}

let bindQueueArguments: any;
if (subscriptionOptions.queueOptions) {
bindQueueArguments = subscriptionOptions.queueOptions.bindQueueArguments;
if (queueOptions) {
bindQueueArguments = queueOptions.bindQueueArguments;
}

const routingKeys = Array.isArray(routingKey) ? routingKey : [routingKey];
Expand Down

0 comments on commit 288c4b8

Please sign in to comment.