This is a sample that reproduces the error, when we create a queue that has been previously deleted.
"use strict";
let rabbit = require("./");
const settings = {
connection: {
user: "guest",
pass: "guest",
server: "127.0.0.1",
heartbeat : 20,
vhost : "vhost",
replyQueue: false
},
exchanges:[
{ name: "test", type: "topic", persistent: true }
],
logging: {
adapters: {
stdOut: { // adds a console logger at the "info" level
level: 6,
bailIfDebug: true
}
}
}
};
rabbit.configure( settings ).done(async function() {
console.log("Server Started");
RunTest();
} );
rabbit.on( "connected", function() {
console.log("************** rabbit has connected");
} );
rabbit.on( "failed", function() {
console.log("************** rabbit has failed");
} );
rabbit.on( "unreachable", function() {
console.log("************** rabbit is unreachable retrying ..");
rabbit.retry();
} );
function CreateAndListenQueue(routeKey,callback,state,tag = "")
{
let queueName = `test.${routeKey}.${tag}`;
let createPromise = rabbit.addQueue(queueName,{durable:false,noAck:true,noBatch:true,autoDelete:true,expires:2 * 60 *1000});
createPromise = createPromise.then(() => {
return rabbit.bindQueue("test",queueName,routeKey);
});
createPromise = createPromise.then(() => {
state.queueName = queueName;
state.handler = rabbit.handle({
queue: queueName, // only handle messages from the queue with this name
type: "#", // handle messages with this type name or pattern
autoNack: true, // automatically handle exceptions thrown in this handler
context: state, // control what `this` is when invoking the handler
handler: callback // allows you to just pass the handle function as an option property
});
state._queueStopped = false;
state.CleanUp = async function() {
if(!this._queueStopped)
{
this._queueStopped = true;
await StopQueue(this.queueName, this.handler);
}
}.bind(state);
return rabbit.startSubscription(queueName);
});
return createPromise;
}
async function StopQueue(queue,handler)
{
await handler.remove();
await rabbit.deleteQueue(queue);
}
function testCallback(msg)
{
}
async function RunTest()
{
{
const state = {};
let procedure = CreateAndListenQueue(`test.msg`, testCallback, state);
await procedure;
await state.CleanUp();
}
{
const state = {};
let procedure = CreateAndListenQueue(`test.msg`, testCallback, state);
await procedure;
await state.CleanUp();
}
}
process.once('SIGINT', async () => {
console.log("Exiting due to SIGINT.....");
await rabbit.shutdown();
});
this is the following error
2017-07-26T10:33:17.513Z [rabbot.io] Attempting acquisition of connection 'default'
2017-07-26T10:33:17.513Z [rabbot.connection] Attempting connection to 'default' (amqp://guest:guest@127.0.0.1:5672/vhost?heartbeat=20)
2017-07-26T10:33:17.575Z [rabbot.connection] Connected to 'default' (amqp://guest:guest@127.0.0.1:5672/vhost?heartbeat=20)
2017-07-26T10:33:17.575Z [rabbot.io] Acquired connection 'default' successfully
** rabbit has connected
2017-07-26T10:33:17.575Z [rabbot.io] Attempting acquisition of channel ''
2017-07-26T10:33:17.575Z [rabbot.io] Attempting acquisition of channel 'test'
2017-07-26T10:33:17.590Z [rabbot.io] Acquired channel '' successfully
2017-07-26T10:33:17.590Z [rabbot.topology] Declaring undefined exchange '' on connection 'default' with the options: {"passive":true}
2017-07-26T10:33:17.590Z [rabbot.io] Acquired channel 'test' successfully
2017-07-26T10:33:17.590Z [rabbot.topology] Declaring topic exchange 'test' on connection 'default' with the options: {}
Server Started
2017-07-26T10:33:17.590Z [rabbot.io] Attempting acquisition of channel 'queue:test.test.msg.'
2017-07-26T10:33:17.606Z [rabbot.io] Acquired channel 'queue:test.test.msg.' successfully
2017-07-26T10:33:17.606Z [rabbot.topology] Declaring queue 'test.test.msg.' on connection 'default' with the options: {"durable":false,"noAck":true,"noBatch":true,"autoDelete":true,"expires":120000,"uniqueName":"test.test.msg."}
2017-07-26T10:33:17.606Z [rabbot.io] Attempting acquisition of channel 'control'
2017-07-26T10:33:17.606Z [rabbot.io] Acquired channel 'control' successfully
2017-07-26T10:33:17.606Z [rabbot.topology] Binding queue 'test.test.msg.' to 'test' on 'default' with keys: ["test.msg"]
2017-07-26T10:33:17.606Z [rabbot.queue] Starting subscription to queue 'test.test.msg.' on 'default'
2017-07-26T10:33:17.606Z [rabbot.queue] Subscription to (untracked) queue test.test.msg. - default started with consumer tag ucmaapp.C:\Windows\system32\cmd.exe - node test.js .7436.test.test.msg.
2017-07-26T10:33:17.622Z [rabbot.queue] Released queue test.test.msg. - default
2017-07-26T10:33:17.622Z [rabbot.queue] Unsubscribing from queue 'test.test.msg.' with tag ucmaapp.C:\Windows\system32\cmd.exe - node test.js .7436.test.test.msg.
2017-07-26T10:33:17.622Z [rabbot.topology] Deleting queue 'test.test.msg.' on connection 'default'
2017-07-26T10:33:17.622Z [rabbot.io] channel 'queue:test.test.msg.' was closed by the user
(node:7436) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: No queue named 'test.test.msg.' for connection 'undefined'. Subscription failed.
Exiting due to SIGINT.....
2017-07-26T10:33:23.184Z [rabbot.connection] Close initiated on connection 'default'
2017-07-26T10:33:23.184Z [rabbot.exchange] Release called on exchange - default (0 messages pending)
2017-07-26T10:33:23.184Z [rabbot.exchange] Release called on exchange test - default (0 messages pending)
2017-07-26T10:33:23.184Z [rabbot.io] channel '' was closed by the user
2017-07-26T10:33:23.199Z [rabbot.io] channel 'test' was closed by the user
2017-07-26T10:33:23.199Z [rabbot.io] channel 'control' was closed by the broker with reason 'No information provided'
2017-07-26T10:33:23.199Z [rabbot.io] connection 'default' was closed by the broker with reason 'No information provided'
2017-07-26T10:33:23.199Z [rabbot.connection] Close on connection 'default' resolved
This is a sample that reproduces the error, when we create a queue that has been previously deleted.
this is the following error
2017-07-26T10:33:17.513Z [rabbot.io] Attempting acquisition of connection 'default' 2017-07-26T10:33:17.513Z [rabbot.connection] Attempting connection to 'default' (amqp://guest:guest@127.0.0.1:5672/vhost?heartbeat=20) 2017-07-26T10:33:17.575Z [rabbot.connection] Connected to 'default' (amqp://guest:guest@127.0.0.1:5672/vhost?heartbeat=20) 2017-07-26T10:33:17.575Z [rabbot.io] Acquired connection 'default' successfully ** rabbit has connected 2017-07-26T10:33:17.575Z [rabbot.io] Attempting acquisition of channel '' 2017-07-26T10:33:17.575Z [rabbot.io] Attempting acquisition of channel 'test' 2017-07-26T10:33:17.590Z [rabbot.io] Acquired channel '' successfully 2017-07-26T10:33:17.590Z [rabbot.topology] Declaring undefined exchange '' on connection 'default' with the options: {"passive":true} 2017-07-26T10:33:17.590Z [rabbot.io] Acquired channel 'test' successfully 2017-07-26T10:33:17.590Z [rabbot.topology] Declaring topic exchange 'test' on connection 'default' with the options: {} Server Started 2017-07-26T10:33:17.590Z [rabbot.io] Attempting acquisition of channel 'queue:test.test.msg.' 2017-07-26T10:33:17.606Z [rabbot.io] Acquired channel 'queue:test.test.msg.' successfully 2017-07-26T10:33:17.606Z [rabbot.topology] Declaring queue 'test.test.msg.' on connection 'default' with the options: {"durable":false,"noAck":true,"noBatch":true,"autoDelete":true,"expires":120000,"uniqueName":"test.test.msg."} 2017-07-26T10:33:17.606Z [rabbot.io] Attempting acquisition of channel 'control' 2017-07-26T10:33:17.606Z [rabbot.io] Acquired channel 'control' successfully 2017-07-26T10:33:17.606Z [rabbot.topology] Binding queue 'test.test.msg.' to 'test' on 'default' with keys: ["test.msg"] 2017-07-26T10:33:17.606Z [rabbot.queue] Starting subscription to queue 'test.test.msg.' on 'default' 2017-07-26T10:33:17.606Z [rabbot.queue] Subscription to (untracked) queue test.test.msg. - default started with consumer tag ucmaapp.C:\Windows\system32\cmd.exe - node test.js .7436.test.test.msg. 2017-07-26T10:33:17.622Z [rabbot.queue] Released queue test.test.msg. - default 2017-07-26T10:33:17.622Z [rabbot.queue] Unsubscribing from queue 'test.test.msg.' with tag ucmaapp.C:\Windows\system32\cmd.exe - node test.js .7436.test.test.msg. 2017-07-26T10:33:17.622Z [rabbot.topology] Deleting queue 'test.test.msg.' on connection 'default' 2017-07-26T10:33:17.622Z [rabbot.io] channel 'queue:test.test.msg.' was closed by the user (node:7436) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: No queue named 'test.test.msg.' for connection 'undefined'. Subscription failed. Exiting due to SIGINT..... 2017-07-26T10:33:23.184Z [rabbot.connection] Close initiated on connection 'default' 2017-07-26T10:33:23.184Z [rabbot.exchange] Release called on exchange - default (0 messages pending) 2017-07-26T10:33:23.184Z [rabbot.exchange] Release called on exchange test - default (0 messages pending) 2017-07-26T10:33:23.184Z [rabbot.io] channel '' was closed by the user 2017-07-26T10:33:23.199Z [rabbot.io] channel 'test' was closed by the user 2017-07-26T10:33:23.199Z [rabbot.io] channel 'control' was closed by the broker with reason 'No information provided' 2017-07-26T10:33:23.199Z [rabbot.io] connection 'default' was closed by the broker with reason 'No information provided' 2017-07-26T10:33:23.199Z [rabbot.connection] Close on connection 'default' resolved