Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: error thrown when queue deleted in amqplib 0.10.0 #303

Merged
merged 1 commit into from Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ChannelWrapper.ts
Expand Up @@ -759,15 +759,15 @@ export default class ChannelWrapper extends EventEmitter {
if (!msg) {
consumer.consumerTag = null;
this._reconnectConsumer(consumer).catch((err) => {
if (err.isOperational && err.message.includes('BasicConsume; 404')) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like amqplib never throws errors with isOperational any more. Upgrading to 0.10.3 in this repo causes this test to fail because of this. (I'll push a fix for that one in just a sec...)

if (err.code === 404) {
// Ignore errors caused by queue not declared. In
// those cases the connection will reconnect and
// then consumers reestablished. The full reconnect
// might be avoided if we assert the queue again
// before starting to consume.
return;
}
throw err;
this.emit('error', err);
});
return;
}
Expand Down
29 changes: 29 additions & 0 deletions test/integrationTest.ts
Expand Up @@ -298,4 +298,33 @@ describe('Integration tests', () => {
await rpcClient.close();
await rpcServer.close();
});

it('should reconnect consumer after queue deletion', async function () {
const queueName = 'testQueue';

connection = new AmqpConnectionManager('amqp://localhost', { reconnectTimeInSeconds: 0.5 });
const channelWrapper = connection.createChannel({
confirm: true,
setup: async (channel: Channel) => {
await channel.assertQueue(queueName, { durable: false, autoDelete: true });
},
});

const result = defer<string>();
await channelWrapper.consume(queueName, (msg) => {
result.resolve(msg.content.toString());
});

await Promise.all([connection.connect(), once(channelWrapper, 'connect')]);

// The deleted queue should cause a reconnect
await channelWrapper.deleteQueue(queueName);

// Await all setup functions to run before sending a message
await once(channelWrapper, 'connect');
await channelWrapper.sendToQueue(queueName, 'hello');

const content = await result.promise;
expect(content).to.equal('hello');
});
});