<commit_before>/* %Z% %W% %I% %E% %U% */
/*
 * <copyright
 * notice="lm-source-program"
 * pids="5755-P60"
 * years="2013,2014"
 * crc="3568777996" >
 * Licensed Materials - Property of IBM
 *
 * 5755-P60
 *
 * (C) Copyright IBM Corp. 2013, 2014
 *
 * US Government Users Restricted Rights - Use, duplication or
 * disclosure restricted by GSA ADP Schedule Contract with
 * IBM Corp.
 * </copyright>
 */

try {
  var mqlight = require('mqlight');
} catch(_) {
  var mqlight = require('../../lib/node_modules/mqlight');
}

try {
  var nopt = require('nopt');
} catch(_) {
  var nopt = require(require.resolve('npm') + '/../../node_modules/nopt');
}

// parse the commandline arguments
var types = {};
var shorthands = { h: ["--help"] };
var parsed = nopt(types, shorthands, process.argv, 2);
var remain = parsed.argv.remain;

if (parsed.help || remain.length < 1) {
  console.log("Usage: recv.js [options] <address_1> ... <address_n>");
  console.log("                        address: //<domain>[/<name>]");
  console.log("");
  console.log("simple message receiver");
  console.log("");
  console.log("Options:");
  console.log("  -h, --help            show this help message and exit");
  if (parsed.help) {
    process.exit(0);
  } else {
    process.exit(1);
  }
}

// extract appropriate values from arguments
var broker = remain[0] || "amqp://0.0.0.0";
var hostname = broker.replace("amqp://", '');
var address = '';
if (hostname.indexOf('/') > -1) {
  address = hostname.substring(hostname.indexOf('/')+1);
  hostname = hostname.substring(0, hostname.indexOf('/'));
}
var port = 5672;
if (hostname.indexOf(':') > -1) {
  var split = hostname.split(':');
  hostname = split[0];
  port = split[1];
}

// connect client to broker
var client = mqlight.createClient(hostname, port, "recv.js");

client.on('connected', function() {
  console.log("Connected to " + hostname + ":" + port + " using client-id " + client.clientId);

  // now subscribe to topic for publications
  var destination = client.createDestination(address, 5000, function(err, address) {
    if (address) {
      console.log("Subscribing to " + address);
    }
  });

  // listen to new message events and process them
  var i = 0;
  destination.on('message', function(msg) {
    console.log('# received message (' + (++i) + ')');
    console.log(msg);
  });
});

<commit_msg>undo multi-address change in recv.js<commit_after>/* %Z% %W% %I% %E% %U% */
/*
 * <copyright
 * notice="lm-source-program"
 * pids="5755-P60"
 * years="2013,2014"
 * crc="3568777996" >
 * Licensed Materials - Property of IBM
 *
 * 5755-P60
 *
 * (C) Copyright IBM Corp. 2013, 2014
 *
 * US Government Users Restricted Rights - Use, duplication or
 * disclosure restricted by GSA ADP Schedule Contract with
 * IBM Corp.
 * </copyright>
 */

try {
  var mqlight = require('mqlight');
} catch(_) {
  var mqlight = require('../../lib/node_modules/mqlight');
}

try {
  var nopt = require('nopt');
} catch(_) {
  var nopt = require(require.resolve('npm') + '/../../node_modules/nopt');
}

// parse the commandline arguments
var types = {};
var shorthands = { h: ["--help"] };
var parsed = nopt(types, shorthands, process.argv, 2);
var remain = parsed.argv.remain;

if (parsed.help || remain.length != 1) {
  console.log("Usage: recv.js [options] <address>");
  console.log("                        address: //<domain>[/<name>]");
  console.log("");
  console.log("simple message receiver");
  console.log("");
  console.log("Options:");
  console.log("  -h, --help            show this help message and exit");
  if (parsed.help) {
    process.exit(0);
  } else {
    process.exit(1);
  }
}

// extract appropriate values from arguments
var broker = remain[0] || "amqp://0.0.0.0";
var hostname = broker.replace("amqp://", '');
var address = '';
if (hostname.indexOf('/') > -1) {
  address = hostname.substring(hostname.indexOf('/')+1);
  hostname = hostname.substring(0, hostname.indexOf('/'));
}
var port = 5672;
if (hostname.indexOf(':') > -1) {
  var split = hostname.split(':');
  hostname = split[0];
  port = split[1];
}

// connect client to broker
var client = mqlight.createClient(hostname, port, "recv.js");

client.on('connected', function() {
  console.log("Connected to " + hostname + ":" + port + " using client-id " + client.clientId);

  // now subscribe to topic for publications
  var destination = client.createDestination(address, 5000, function(err, address) {
    if (address) {
      console.log("Subscribing to " + address);
    }
  });

  // listen to new message events and process them
  var i = 0;
  destination.on('message', function(msg) {
    console.log('# received message (' + (++i) + ')');
    console.log(msg);
  });
});


{'fraction_non_alphanumeric': 0.18936170212765957, 'fraction_numerical': 0.026595744680851064, 'mean_word_length': 3.344731977818854, 'pattern_counts': {'":': 2, '<': 15, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4576776', 'n_tokens_mistral': 1654, 'n_tokens_neox': 1560, 'n_words': 399}