Created
March 3, 2017 05:54
-
-
Save bubuzzz/4ba89fd1a61f403e189314cdda1515be to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var AMQPClient = require('amqp10').Client; | |
var Promise = require('bluebird'); | |
var Policy = require('amqp10').Policy; | |
var client = new AMQPClient(Policy.ActiveMQ); // Uses PolicyBase default policy | |
var url = "amqp://admin:admin@Thais-MBP:5672"; | |
client.connect(url).then(function() { | |
return Promise.all([ | |
client.createReceiver('topic://amq.topic'), | |
client.createSender('topic://amq.topic') | |
]); | |
}).spread(function(receiver, sender) { | |
receiver.on('errorReceived', function(err) { | |
console.log('.................there is errro'); | |
console.log(err); | |
}); | |
receiver.on('message', function(message) { | |
console.log('[' + message.body.name + ']', message.body.msg); | |
}); | |
process.stdin.resume(); | |
process.stdin.setEncoding('utf8'); | |
var util = require('util'); | |
process.stdin.on('data', function(text) { | |
sender.send({ | |
'name': process.argv[2], | |
'msg': text | |
}); | |
if (text === 'quit\n') { | |
done(); | |
} | |
}); | |
}).error(function(err) { | |
console.log("error: ", err); | |
}); | |
function done() { | |
console.log('Now that process.stdin is paused, there is nothing more to do.'); | |
process.exit(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment