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

Unhandled rejection error: Channel ended, no reply will be forthcoming #97

Open
vunguyen11295 opened this issue Sep 9, 2019 · 3 comments

Comments

@vunguyen11295
Copy link

"use strict";
const amqp = require('amqp-connection-manager');
const mqcon = require('./mqConnection');
const AMQP_URL = mqcon.getAMQPURL();

module.exports.success = function success(res, next, data) {
_respond(res, next, 'success', data, 200);
}

module.exports.failure = function failure(res, next, data, http_code) {
_respond(res, next, 'failure', data, http_code);
}

module.exports.publish = async function (msgKey, msgPayload) {
const connection = await amqp.connect(AMQP_URL);
const exch = 'taskch';

// Create a channel wrapper
const channelWrapper = await connection.createChannel({
setup: channel => channel.assertExchange(exch, 'direct', { durable: true })
});

await channelWrapper.publish(exch, msgKey, Buffer.from(msgPayload))
.then(function () {
// console.log("Message sent", msgPayload);
})
.catch(err => {
console.log("[ERROR] Message was rejected:", err.stack);
channelWrapper.close();
connection.close();
});

};

module.exports.consume = async function (ex, qname, msgKey, invkFn) {
const connection = await amqp.connect(AMQP_URL);
const onMessage = data => {
channelWrapper.ack(data);
//call the function to be invoked on receipt of a message
invkFn(data);
}

// Set up a channel listening for messages in the queue.
const channelWrapper = connection.createChannel({
setup: channel =>
Promise.all([
channel.assertExchange(ex, 'direct', { durable: true }),
channel.assertQueue(qname, { exclusive: false }), // , autoDelete: true
channel.bindQueue(qname, ex, msgKey),
channel.consume(qname, onMessage)
])
});

channelWrapper.waitForConnect()
.then(function () {
console.log("[INFO] Waiting for messages in %s. To exit press CTRL+C", qname);
});
}

This is my code, please help!

@nieverbe
Copy link

@vunguyen11295, Do you already have a solution for this?
Seeing the same on my implementation..

@morigs
Copy link

morigs commented Feb 26, 2020

Try to wrap await channelWrapper.waitForConnect() with try-catch (now you have only then without catch)

Also do not use await in await connection.createChannel. createChannel doesn't return a Promise

@dorshay6
Copy link

I am having a similar problem. It looks like it happens after logs of mirroring of messages inside the cluster, I think the channel state was not updated for some reason

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants