Created
July 24, 2019 13:37
-
-
Save tlcheah2/e56f148e606237edcf81d80b8b67753b to your computer and use it in GitHub Desktop.
TimerService
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
// This is timer producer | |
const INTERVAL_DURATION = 60000; | |
const url = process.env.CLOUDAMQP_URL || "amqp://localhost"; | |
const amqp = require('amqplib'); | |
exports.startTimer = () => { | |
amqp.connect(url).then((connection) => { | |
connection.createChannel().then((channel) => { | |
const exchange = 'quote'; | |
channel.assertExchange(exchange, 'direct', {durable: false}); | |
// channel.assertQueue(quote_queue, { durable: true}); | |
setInterval(() => { | |
const message = "Let go get the quote"; | |
console.log('send to queue', message); | |
// channel.sendToQueue(quote_queue, Buffer.from(message), { | |
// persistent: true | |
// }); | |
channel.publish(exchange, '', Buffer.from(message)); | |
}, INTERVAL_DURATION) | |
}); | |
}).catch((err) => { | |
console.error('Connect amqp failed', err); | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment