Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var amqp = require('amqplib/callback_api');
- var readline = require('readline');
- amqp.connect('amqp://TMDG2022:TMDG2022@rmq2.pptik.id:5672/', function(error0, connection) {
- if (error0) {
- throw error0;
- }
- connection.createChannel(function(error1, channel) {
- if (error1) {
- throw error1;
- }
- var queue = 'testing';
- // Create a readline interface to read from the keyboard
- var rl = readline.createInterface({
- input: process.stdin,
- output: process.stdout
- });
- // Function to send a message to the queue
- function sendMessage() {
- rl.question('Enter a message to send: ', function(msg) {
- channel.assertQueue(queue, {
- durable: false
- });
- channel.sendToQueue(queue, Buffer.from(msg));
- console.log(" [x] Sent %s", msg);
- // Ask for another message or close the connection
- rl.question('Do you want to send another message? (yes/no): ', function(answer) {
- if (answer.toLowerCase() === 'yes') {
- sendMessage();
- } else {
- connection.close();
- process.exit(0);
- }
- });
- });
- }
- sendMessage(); // Start the process by sending the first message
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement