noodlefrenzy / node-amqp10

amqp10 is a promise-based, AMQP 1.0 compliant node.js client
MIT License
134 stars 56 forks source link

errorReceived events don't work #344

Open swilliams-a3digital opened 6 years ago

swilliams-a3digital commented 6 years ago

I found these examples from your samples:

sender.on('errorReceived', function (tx_err) { console.warn('===> TX ERROR: ', tx_err); }); receiver.on('errorReceived', function (rx_err) { console.warn('===> RX ERROR: ', rx_err); });

But they don't work. If I bring down my activemq server I don't get any errorReceived events.

swilliams-a3digital commented 6 years ago

It looks like your sample documentation is out of date. I read through the code and this worked: const AMQPClient = require("amqp10").Client; const activeMQPolicy = require("amqp10").Policy; const client = new AMQPClient(activeMQPolicy.ActiveMQ); client.on(AMQPClient.ErrorReceived, (err) => { console.log(err received ${err}); });

swilliams-a3digital commented 6 years ago

Here is what I ended up doing for error handling. Basically I wanted to keep the connection going and re-establish my receiver on disconnect. This was able to survive bringing my active MQ server down and up. Nothing else I tried could survive that and keep working. If there is a better way, please advise.

const AMQPClient = require("amqp10").Client; const Promise = require("bluebird"); const activeMQPolicy = require("amqp10").Policy; // not sure if this is necessary or wise activeMQPolicy.Default.reconnect.retries = 10000; activeMQPolicy.ActiveMQ.reconnect.retries = 10000; const client = new AMQPClient(activeMQPolicy.ActiveMQ); subscriber = null; client.on('connected', () => { console.log(connected to AMQP Broker); client.createReceiver("logging.test").then(r => { subscriber = r; r.on("message", message => console.log(Rx message: ${message.body})); }); }); client.on(AMQPClient.ConnectionClosed, () => { console.log(amqp connection closed); subscriber = null; }); client.on(AMQPClient.ErrorReceived, (err) => { console.log(err received ${err}); }); let url = "amqp://user:notmypasword@localhost:5672"; client.connect(url) .then(c => { console.log('connection initialized'); return null; });