Last active
September 7, 2016 18:04
-
-
Save yunghoy/df87cfbdcd4e7c287fb72826320edd0d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://stackoverflow.com/questions/38841204/events-js160-throw-er-unhandled-error-event | |
--- | |
events.js:160 | |
throw er; // Unhandled 'error' event | |
^ | |
Error: Channel closed by server: 404 (NOT-FOUND) with message "NOT_FOUND - no exchange 'exchange_name_final' in vhost '/'" | |
at Channel.C.accept (/home/nilath/test/rabbitmq/node_modules/amqplib/lib/channel.js:406:17) | |
at Connection.mainAccept [as accept] (/home/nilath/test/rabbitmq/node_modules/amqplib/lib/connection.js:63:33) | |
at Socket.go (/home/nilath/test/rabbitmq/node_modules/amqplib/lib/connection.js:476:48) | |
at emitNone (events.js:86:13) | |
at Socket.emit (events.js:185:7) | |
at emitReadable_ (_stream_readable.js:438:10) | |
at emitReadable (_stream_readable.js:432:7) | |
at readableAddChunk (_stream_readable.js:183:13) | |
at Socket.Readable.push (_stream_readable.js:130:10) | |
at TCP.onread (net.js:535:20) | |
--- | |
--- | |
Error: test | |
at Error (native) | |
at /home/nilath/test/rabbitmq/recv2.js:30:8 | |
at undefined.next (native) | |
at step (/home/nilath/test/rabbitmq/recv2.js:36:191) | |
at /home/nilath/test/rabbitmq/recv2.js:36:368 | |
at run (/usr/local/lib/node_modules/babel-cli/node_modules/core-js/modules/es6.promise.js:87:22) | |
at /usr/local/lib/node_modules/babel-cli/node_modules/core-js/modules/es6.promise.js:100:28 | |
at flush (/usr/local/lib/node_modules/babel-cli/node_modules/core-js/modules/_microtask.js:18:9) | |
at _combinedTickCallback (internal/process/next_tick.js:67:7) | |
at process._tickDomainCallback (internal/process/next_tick.js:122:9) | |
--- | |
Finally!!!! Found the solution!!! | |
// babel-node recv2.js "#" | |
// babel-node recv2.js "kern.*" | |
const amqp = require('amqplib'); | |
const args = process.argv.slice(2); | |
if (args.length == 0) { | |
console.log("Usage: receive_logs_topic.js <facility>.<severity>"); | |
process.exit(1); | |
} | |
const EXCHANGE_NAME = 'exchange_name'; | |
const EXCHANGE_TYPE = 'x-recent-history'; | |
const EXCHANGE_OPTION = { | |
durable: true, | |
autoDelete: true, | |
arguments: { | |
'x-recent-history-length': 10 | |
} | |
}; | |
async function main() { | |
const conn = await amqp.connect('amqp://localhost'); | |
/* | |
conn.on('error', function(e) { | |
console.log("[conn] Error from amqp: ", e); | |
}); | |
*/ | |
const channel = await conn.createChannel(); | |
/* | |
channel.on('error', function(e) { | |
console.log("Error from amqp: ", e); | |
}); | |
*/ | |
await channel.assertExchange(EXCHANGE_NAME, EXCHANGE_TYPE, EXCHANGE_OPTION); | |
/* | |
try { | |
const check = await channel.checkExchange('exchange_name_final'); | |
throw Error('test'); | |
} catch(er) { | |
console.log(er); | |
} | |
*/ | |
await channel.bindExchange('exchange_name_fina', EXCHANGE_NAME, '', {}); | |
/* | |
const q = await channel.assertQueue('', {exclusive: true}); | |
console.log(' [*] Waiting for logs. To exit press CTRL+C'); | |
args.forEach((key) => channel.bindQueue(q.queue, EXCHANGE_NAME, key)); | |
channel.consume(q.queue, print, {noAck: true}); | |
*/ | |
} | |
function print(msg) { | |
console.log(" [x] %s:'%s'", msg.fields.routingKey, msg.content.toString()); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment