<commit_before>var debug = require('debug')('amqp-nice:server')
var _ = require('lodash').runInContext()
var Broker = require('../lib/amqp/Broker')
var defaultConfig = require('../lib/config/defaults')
var uuid = require('node-uuid').v4()

_.mixin({ 'defaultsDeep': require('merge-defaults') });

var config = _.defaultsDeep({
    vhosts: {
        'v1': {
            namespace: uuid,
            exchanges: {
                'e1': {
                    durable: false
                }
            },
            queues: {
                'q1': {
                    durable: false
                }
            },
            bindings: {
                'b1': {
                    source: 'e1',
                    destination: 'q1'
                }
            },
        }
    },
    publications: {
        'p1': {
            exchange: 'e1',
            vhost: 'v1',
            confirm: true
        },
        'p2': {
            queue: 'q1',
            vhost: 'v1',
            confirm: true
        }
    },
    subscriptions: {
        's1': {
            queue: 'q1',
            vhost: 'v1'
        }
    }
}, defaultConfig)

var sent = 0
var received = 0

Broker.create(config, function(err, broker) {
    if (err) console.error(err) || process.exit(1)

    broker.on('error', function(err) {})

    process.on('SIGINT', function() {
        broker.nuke(function() {
            console.log('Sent', sent)
            console.log('Received', received)
            process.exit()
        })
    })

    soakPublication(broker, 'p1')
    soakPublication(broker, 'p2')
    broker.subscribe('s1', function(err, message, content) {
        received++
    }, function(err) {
        if (err) console.log(err)
    })

    debug('Come and have a go if you think you\'re hard enough')
})


function soakPublication(broker, publication, interval) {
    setInterval(function() {
        broker.publish(publication, 'This is a test message', function(err) {
            if (err) console.error(err.message)
            sent++
        })
    }, interval || 1000).unref()
}<commit_msg>Fixing example<commit_after>var debug = require('debug')('amqp-nice:server')
var _ = require('lodash').runInContext()
var Broker = require('../lib/amqp/Broker')
var defaultConfig = require('../lib/config/defaults')
var uuid = require('node-uuid').v4()

_.mixin({ 'defaultsDeep': require('merge-defaults') });

var config = _.defaultsDeep({
    vhosts: {
        'v1': {
            namespace: uuid,
            exchanges: {
                'e1': {
                    durable: false
                }
            },
            queues: {
                'q1': {
                    durable: false
                }
            },
            bindings: {
                'b1': {
                    source: 'e1',
                    destination: 'q1'
                }
            },
        }
    },
    publications: {
        'p1': {
            exchange: 'e1',
            vhost: 'v1',
            confirm: true
        },
        'p2': {
            queue: 'q1',
            vhost: 'v1',
            confirm: true
        }
    },
    subscriptions: {
        's1': {
            queue: 'q1',
            vhost: 'v1'
        }
    }
}, defaultConfig)

var sent = 0
var received = 0

Broker.create(config, function(err, broker) {
    if (err) console.error(err) || process.exit(1)

    process.on('SIGINT', function() {
        broker.nuke(function() {
            console.log('Sent', sent)
            console.log('Received', received)
            process.exit()
        })
    })

    soakPublication(broker, 'p1')
    soakPublication(broker, 'p2')
    broker.subscribe('s1', function(err, message, content) {
        received++
    }, function(err) {
        if (err) console.log(err)
    })

    debug('Come and have a go if you think you\'re hard enough')
})


function soakPublication(broker, publication, interval) {
    setInterval(function() {
        broker.publish(publication, 'This is a test message', function(err) {
            if (err) console.error(err.message)
            sent++
        })
    }, interval || 100).unref()
}
{'fraction_non_alphanumeric': 0.14617618586640851, 'fraction_numerical': 0.012342691190706679, 'mean_word_length': 1.521659548505186, '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': '7013585', 'n_tokens_mistral': 1254, 'n_tokens_neox': 1222, 'n_words': 249}