Created
May 21, 2017 07:43
-
-
Save boogie/79dc497f0b9fe80fad0aa0ef3ef52d98 to your computer and use it in GitHub Desktop.
WRONG implementation: RabbitMQ client closes the connection after 2 secs
This file contains 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
#!/usr/bin/env node | |
'use strict'; | |
const amqp = require('amqplib'); | |
const sleep = async (ms) => new Promise(resolve => setTimeout(resolve, ms)); | |
(async () => { | |
const conn = await amqp.connect('amqp://localhost:9520'); | |
process.once('SIGINT', () => conn.close()); | |
const ch = await conn.createChannel(); | |
await ch.assertQueue('hello', { durable: false }); | |
await ch.prefetch(1); | |
await ch.consume('hello', async (msg) => { | |
console.log(" [x] Received '%s'", msg.content.toString()); | |
await sleep(500); | |
ch.ack(msg); | |
}); | |
setTimeout(()=>{ | |
ch.close(); | |
console.log(' [*] Finished'); | |
}, 2000); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment