Create and declare exchange.

@param string       $exchangeClass
@param \AMQPChannel $channel
@param array        $exchangeOptions

@return \AMQPExchange
170002
protected function createExchange($exchangeClass, $channel, array $exchangeOptions)
    {
        /** @var \AMQPExchange $exchange */
        $exchange = new $exchangeClass($channel);
        $exchange->setName($exchangeOptions['name']);

        // If the type is not specified, the exchange must exist
        if (isset($exchangeOptions['type'])) {
            $exchange->setType($exchangeOptions['type']);
            $exchange->setArguments($exchangeOptions['arguments']);
            $exchange->setFlags(
                ($exchangeOptions['passive'] ? AMQP_PASSIVE : AMQP_NOPARAM) |
                ($exchangeOptions['durable'] ? AMQP_DURABLE : AMQP_NOPARAM) |
                ($exchangeOptions['auto_delete'] ? AMQP_AUTODELETE : AMQP_NOPARAM)
            );
            $exchange->declareExchange();
        }

        return $exchange;
    }
787182
public function addChannel(ChannelOptions $channel)
    {
        $key = $channel->getKey();
        $this->channels[$key] = $channel;
        return $this;
    }
1235340
def setup_exchange(self, exchange_name):
        
        _logger.debug('Declaring exchange %s', exchange_name)
        self._channel.exchange_declare(self.on_exchange_declareok,
                                       exchange_name,
                                       self.EXCHANGE_TYPE,
                                       durable=True,
                                       passive=True)
737918
public function createContext(array $options, MessageInterface $message = null, Exchange $exchange = null, \Exception $exception = null)
    {
        $context = [
            self::CONTEXT_OPTIONS => $options,
            self::CONTEXT_VARS => [],
            self::CONTEXT_RESULTS => [],
        ];

        if ($exchange) {
            $context[self::CONTEXT_EXCHANGE] = $exchange;
            if (!$message) {
                $message = $exchange->getIn();
            }
        }

        if ($message) {
            $context[self::CONTEXT_MSG] = $message;
            $context[self::CONTEXT_HEADERS] = $message->getHeaders();
            $context[self::CONTEXT_BODY] = $message->getBody();
        }

        if ($exception) {
            $context[self::CONTEXT_EXCEPTION] = $exception;
        }

        return $context;
    }
1175694
def get_exchange(connection, name, create=False):
    
    exchange = Exchange(name, type="topic", passive=not create)

    # bind the exchange to our connection so operations can be performed on it
    bound_exchange = exchange(connection)

    # ensure the exchange exists.  Throw an error if it was created with
    # passive=True and it doesn't exist.
    bound_exchange.declare()

    return bound_exchange
935632
public function deleteExchange($name, array $options = [], callable $callback = null)
    {
        $ifUnused = array_key_exists('ifUnused', $options) ? (bool)$options['ifUnused'] : null;
        $noWait = array_key_exists('noWait', $options) ? (bool)$options['noWait'] : null;

        $outputFrame = Exchange\ExchangeDeleteFrame::create($name, $ifUnused, $noWait);
        $outputFrame->frameChannelId = $this->id;
        $this->connection->command($outputFrame);

        if (is_callable($callback)) {
            $this->on(self::EVENT_ON_CHANNEL_DELETE_EXCHANGE_CALLBACK, $callback);
        }
    }
507954
private synchronized void createChannel(String channel) {
        if (!channelExists(channel)) {
            Queue queue = new Queue(channel, true, false, true);
            admin.declareQueue(queue);
            Binding binding = new Binding(channel, DestinationType.QUEUE, exchange.getName(), channel + ".#", null);
            admin.declareBinding(binding);
        }
    }
399235
public function exchangeBinding($vhost, $source, $destination)
    {
        return $this->client->send(sprintf('/api/bindings/%s/e/%s/e/%s', urlencode($vhost), urlencode($source), urlencode($destination)));
    }
159209
public static void declareApplicationExchanges( String domain, String applicationName, Channel channel )
	throws IOException {

		// "topic" is a keyword for RabbitMQ.
		if( applicationName != null ) {
			String exch = buildExchangeNameForAgent( domain, applicationName );
			channel.exchangeDeclare( exch, "topic" );
		}
	}
1151094
public function setOptions(array $options)
    {
        if (isset($options['exchange'])) {
            $this->exchange = $options['exchange'];
        }
        if (isset($options['exchange'])) {
            if (!is_string($options['exchange'])) {
                throw new \UnexpectedValueException('exchange value is not a string, a string is required');
            }
            $this->exchange = $options['exchange'];
            unset($options['exchange']);
        }
        if (isset($options['queue'])) {
            if (isset($options['queue']['arguments'])) {
                $this->queueOptions = $options['queue'];
            }
            unset($options['queue']);
        }
        /*
         * @deprecated use of $options['uri'] is deprecated in favor of $options['connection']
         * this block is meant to provide reverse comparability 
         */
        if (!isset($options['connection']) && isset($options['uri'])) {
            trigger_error(
                'the use of `uri` in config options is no longer support for Rhubarb version >= 3.1',
                E_USER_DEPRECATED
            );
            $options['connection'] = $options['uri'];
            unset($options['connection']);
        } elseif (isset($options['uri'])) {
            trigger_error('as of Rhubarb version >= 3.1 `uri` config options is unsupported, you must not implement ' .
                '`connection` and `uri` together', E_NOTICE);
            unset($options['connection']);
        }
        if (isset($options['connection'])) {
            $uri = parse_url($options['connection']);
            if (!isset($uri['port'])) {
                $uri['scheme'] == 'amqps' ? 5673 : $this->options['connection']['port'];
            } else {
                $port = isset($uri['port']) ? $uri['port'] : $this->options['connection']['port'];
            }
            unset($options['connection']);
            $options['connection']['host'] = $uri['host'];
            $options['connection']['port'] = $port;
            $options['connection']['vhost'] = isset($uri['path']) ? $uri['path'] : $this->options['connection']['path'];
            /* I don't like it but to ensure that all parties are happy this is necasary */
            $options['connection']['vhost'] = preg_replace('#^/#', null, $options['connection']['vhost']);
            $options['connection']['login'] = isset($uri['username']) ? $uri['username'] : $this->options['connection']['login'];
            $options['connection']['password'] = isset($uri['pass']) ? $uri['pass'] : $this->options['connection']['password'];
            $this->options['connection'] = $options['connection'];
        }
        return $this;
    }
299415
public static function Mx($preference, $exchange)
    {
        $rdata = new MX();
        $rdata->setPreference($preference);
        $rdata->setExchange($exchange);

        return $rdata;
    }
1084906
protected function doProcess(Exchange $exchange, SerializableArray $processingContext)
    {
        $itinerary = $exchange->getItinerary();

        if ($itinerary->getProcessorIdsCount() > 0) {
            $exchangeBackup = clone $exchange;

            // Take the next processor
            $processorId = $itinerary->shiftProcessorId();
            if (!$this->container->has($processorId)) {
                throw new \RuntimeException("Processor with $processorId not found in container.");
            }
            $processor = $this->container->get($processorId);
            if (!$processor instanceof ProcessorInterface) {
                throw new \RuntimeException('Processors must implement ProcessorInterface.');
            }

            // Prepend this processor
            $itinerary->unShiftProcessorId($this->getId());

            try {
                $processor->process($exchange);
            } catch (ProcessingException $exception) {
                $originalException = $exception->getOriginalException();

                // We try to catch the exception
                foreach ($this->catches as $catch) {
                    if ($this->evaluator->evaluateWithExchange($catch->getCondition(), $exchange, $originalException)) {
                        $exchange->setIn($exchangeBackup->getIn());
                        $exchange->setOut(null);
                        $exchange->setItinerary($catch->getItinerary());
                        if ($this->finallyItinerary) {
                            $exchange->getItinerary()->append($this->finallyItinerary);
                        }

                        return;
                    }
                }

                // If it's not catch, we just let go, if the exchange is retried, we will come to this processor again
                throw $originalException;
            }
        } elseif ($this->finallyItinerary) {
            $exchange->getItinerary()->prepend($this->finallyItinerary);
        }
    }
1286792
public function dial($channel, array $options = array())
    {
        $start = time();
        array_unshift($options, $channel);
        $result = new DialResult($this->exec('Dial', $options));
        $end = time();
        $result->setPeerName($this->getFullVariable('DIALEDPEERNAME'));
        $result->setPeerNumber($this->getFullVariable('DIALEDPEERNUMBER'));
        $result->setDialedTime($end - $start);
        $result->setAnsweredTime($this->getFullVariable('ANSWEREDTIME'));
        $result->setDialStatus($this->getFullVariable('DIALSTATUS'));
        $result->setDynamicFeatures($this->getFullVariable('DYNAMIC_FEATURES'));
        return $result;
    }
1253420
def bind_to_channel(self):
        
        if self.channel.code_name != self.user.prv_exchange:
            channel = self._connect_mq()
            channel.exchange_bind(source=self.channel.code_name, destination=self.user.prv_exchange)
522300
protected function doProcess(Exchange $exchange, SerializableArray $processingContext)
    {
        if (empty($this->exceptionClass)) {
            throw new \RuntimeException('Exception class not found');
        }

        /** @var ExchangeAwareInterface $exception */
        $exception = new $this->exceptionClass($this->exceptionMessage);

        throw $exception;
    }
1287330
public function exchange($name, $options = [])
    {
        if (empty($this->_exchanges[$name])) {
            $channel = $this->channel($name, $options);
            $exchange = new AMQPExchange($channel);
            $exchange->setName($name);

            if (!empty($options['type'])) {
                $exchange->setType($options['type']);
            }

            if (!empty($options['flags'])) {
                $exchange->setFlags($options['flags']);
            }

            $this->_exchanges[$name] = $exchange;
        }

        return $this->_exchanges[$name];
    }
564038
function(options) {
    'use strict';

    var client = this,
        log = options.log,
        socketHost = options.socketHost,
        hubName = options.hubName,
        hub;

    /**
     * open the public/private channels to begin exchanges
     */
    this.subscribe = function(channelName, handler, callback) {
        client.createHub();

        if (typeof handler !== 'function') {
            throw new Error('must subscribe with a handler, using default...');
        }

        log.info('open the access channel: ', channelName);

        hub.subscribe( channelName, handler ).then(function() {
            log.info('channel ', channelName, ' now alive...');

            if (callback) {
                callback( channelName );
            }
        });
    };

    /**
     * wrap the request message and publish to the specified channel
     *
     * @param channel - the channel name
     * @param id - the ssid
     * @param request - the message body
     */
    this.publish = function(channel, id, request) {
        var message = client.wrapMessage(id, request);

        if (log.isDebug()) {
            log.debug('publish to ', channel, ', message: ', JSON.stringify( message ));
        }

        hub.publish( channel, message );
    };

    /**
     * create the message hub from socket host
     *
     * @returns the message hub
     */
    this.createHub = function() {
        if (!hub) {
            hub = new Faye.Client( socketHost + hubName, { timeout:45 });
        }

        return hub;
    };

    /**
     * create the standard wrapper
     *
     * @param request a request object
     * @returns the wrapped message request
     */
    this.wrapMessage = function(id, request) {
        var message = {
            ts:Date.now(),
            message:request
        };

        if (id) {
            message.id = id;
        }

        return message;
    };

    // constructor validations
    if (!log) throw new Error('access client must be constructed with a log');
}