Skip to content

Instantly share code, notes, and snippets.

@alifrizkip
Last active April 11, 2018 02:42
Show Gist options
  • Save alifrizkip/02145218e298367431a2fe04573aca83 to your computer and use it in GitHub Desktop.
Save alifrizkip/02145218e298367431a2fe04573aca83 to your computer and use it in GitHub Desktop.
Work Queue taskProducer.js RabbitMQ
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