Last active
April 11, 2018 02:42
-
-
Save alifrizkip/02145218e298367431a2fe04573aca83 to your computer and use it in GitHub Desktop.
Work Queue taskProducer.js RabbitMQ
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
const amqp = require('amqplib/callback_api') // import library amqplib | |
amqp.connect('amqp://localhost', (err, conn) => { | |
conn.createChannel((err, ch) => { | |
const q = 'task_queue' // Nama antrian adalah 'task_queue' | |
const msg = process.argv.slice(2).join(' ') || 'Hello World!' | |
ch.assertQueue(q, { durable: true }) // Membuat antrian 'task_queue' | |
ch.sendToQueue(q, new Buffer(msg), { persistent: true }) // Mengirim pesan tugas ke antrian | |
console.log(`[x] Sent '%s'`, msg) | |
}) | |
setTimeout(() => { | |
conn.close() | |
process.exit(0) | |
}, 500) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment