+os              = require 'os'
 _               = require 'lodash'
 assert          = require 'assert'
 amqp            = require 'amqp'

        logger.trace("create exchange: %s", options.exchange)

        exch_deferred = Q.defer()
        exch_name = options.channel

        exch_options =
            type: options.type or 'topic'
            autoDelete: false
            durable: options.durable

        logger.trace("create exchange instance", {exch_name, exch_options})
        connection.exchange(options.channel, exch_options, exch_deferred.resolve)

        exch_deferred.promise

module.exports = (setup, options) ->
    setup = {server: setup} if _.isString(setup)

        assert _.isObject(exchange), "exchange required"
        assert _.isString(options.topic), "topic option require"

        binding_key = if options.partition then "10" else options.topic
        bound_queue_deferred = Q.defer()

        logger.trace("binding queue to exchange", {queue: queue.name, exchange: exchange.name, binding_key})
        queue.bind(exchange, binding_key)
        queue.on 'queueBindOk', ->
            logger.trace("queue and exchange bound", {binding_key})
