var Rx = require('rx');
var rabbit = require('amqp');

module.exports = {
	configure: function(config) {
		var exchangeStream = new Rx.Subject();

		var connection = rabbit.createConnection({ host: config.host, login: config.login, password: config.password });
		var connected = Rx.Observable.fromEvent(connection, 'ready');
		connected.subscribe(function() {
			connection.exchange(config.exchange, {
				type: 'direct',
				durable: true,
			}, function(exchange) {
				exchangeStream.onNext(exchange);
			});
		}, function(error) {
			console.log('- an error occurred connecting to rabbit -');
			if (error) { console.log(error); }
		});

		return exchangeStream;
	}
};

var Rx = require('rx');
var rabbit = require('amqp');

module.exports = {
	configure: function(config) {
		var exchangeStream = new Rx.Subject();

		var connection = rabbit.createConnection({ host: config.host, login: config.login, password: config.password });
		var connected = Rx.Observable.fromEvent(connection, 'ready');
		connected.subscribe(function() {
			connection.exchange(config.exchange, {
				type: 'direct',
				durable: true,
				autoDelete: false,
			}, function(exchange) {
				exchangeStream.onNext(exchange);
			});
		}, function(error) {
			console.log('- an error occurred connecting to rabbit -');
			if (error) { console.log(error); }
		});

		return exchangeStream;
	}
};

Set log exchange to persist and not auto delete. We'll want log messages to queue even if nobody is picking them up.
Set log exchange to persist and not auto delete. We'll want log messages to queue even if nobody is picking them up.
