<commit_before>
var simplequeue = require('../..');
var Message = simplequeue.Message;

var client = simplequeue.createRemoteClient();

function getRandomInteger(from, to) {
    return from + Math.floor(Math.random()*(to-from));
}

function Consumer(queue) {
    var n = 0;
    var self = this;
    
    this.process = function() {
        queue.getMessage(function (err, msg) {
            if (err) {
                console.log(err);
            }
            else {
                console.log('Processing ' + msg.payload);
            }
            
            setTimeout(self.process, getRandomInteger(500, 1000));
        });
    }
}

client.on('remote', function(remote) {
    remote.createQueue('queue', function(err, queue) {
        if (err) {
            console.log(err);
            process.exit(1);
        }
        
        (new Consumer(queue)).process();
    });
});
<commit_msg>Fixing consumer in distributed example<commit_after>
var simplequeue = require('../..');
var Message = simplequeue.Message;

var client = simplequeue.createRemoteClient();

function getRandomInteger(from, to) {
    return from + Math.floor(Math.random()*(to-from));
}

function Consumer(queue) {
    var n = 0;
    var self = this;
    
    this.process = function() {
        queue.getMessage(function (err, msg) {
            if (err) {
                console.log(err);
            }
            else if (msg != null) {
                console.log('Processing ' + msg.payload);
            }
            
            setTimeout(self.process, getRandomInteger(500, 1000));
        });
    }
}

client.on('remote', function(remote) {
    remote.createQueue('queue', function(err, queue) {
        if (err) {
            console.log(err);
            process.exit(1);
        }
        
        (new Consumer(queue)).process();
    });
});

{'fraction_non_alphanumeric': 0.14472252448313383, 'fraction_numerical': 0.009793253536452665, 'mean_word_length': 1.90521327014218, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '3946954', 'n_tokens_mistral': 542, 'n_tokens_neox': 523, 'n_words': 105}