var container = require('rhea');
var args = require('yargs').options({
'm': { alias: 'messages', default: 10, describe: 'number of messages to send'},
'n': { alias: 'address', default: 'jms.queue.examples_nevim_neco_pepa', describe: 'name of node (e.g. queue) to which messages are sent'},
'p': { alias: 'port', default: 5672, describe: 'port to connect to'},
'h': { alias: 'host', default: "10.34.124.125", describe: 'ip host'},
'u': { alias: 'username', default: "admin", describe: 'username'},
's': { alias: 'password', default: "admin", describe: 'password'},
}).help('help').argv;
var confirmed = 0, sent = 0;
var total = args.messages;
var message = {};
message['body'] = {};
message.body = "test string message"
container.on('sendable', function (context) {
while (context.sender.sendable() && sent < total) {
sent++;
console.log('sent ' + sent);
context.sender.send(message);
}
});
container.on('accepted', function (context) {
if (++confirmed === total) {
console.log("all messages confirmed")
context.connection.close()
}
});
container.on('disconnected', function (context) {
sent = confirmed;
});
container.connect({'username': args.username, 'password': args.password, 'host': args.host, 'port':args.port}).open_sender(args.address);