Called when the RabbitMQ accepts the channel open request.

        :param pika.channel.Channel channel: The channel opened with RabbitMQ
4422
def on_rabbitmq_channel_open(self, channel):
        
        LOGGER.info('Channel %i is opened for communication with RabbitMQ',
                    channel.channel_number)
        self._set_rabbitmq_channel(channel)
        self._publish_deferred_messages()
1009857
def connections(self, wait):
        
        while wait:
            try:
                params = pika.ConnectionParameters(host=self.rmq_host,
                                                   port=self.rmq_port)
                connection = pika.BlockingConnection(params)
                self.channel = connection.channel()
                self.channel.exchange_declare(exchange='topic_recs',
                                              exchange_type='topic')

                result = self.channel.queue_declare()
                self.queue_name = result.method.queue
                self.es_conn = Elasticsearch([{'host': self.es_host,
                                               'port': self.es_port}])
                wait = False
                print('connected to rabbitmq and elasticsearch...')
            except Exception as e:  # pragma: no cover
                print(str(e))
                print('waiting for connection to rabbitmq...' + str(e))
                time.sleep(2)
                wait = True
1211516
async def listener(self, channel):
        
        while True:
            message = await self.channel_layer.receive(channel)
            if not message.get("type", None):
                raise ValueError("Worker received message with no type.")
            # Make a scope and get an application instance for it
            scope = {"type": "channel", "channel": channel}
            instance_queue = self.get_or_create_application_instance(channel, scope)
            # Run the message into the app
            await instance_queue.put(message)
1228489
def open_channel(self):
        
        logger.info('Creating a new channel')
        self._connection.channel(on_open_callback=self.on_channel_open)
6445
def check_channel_shell_request(self, channel):
        ''''''
        try:
            self.channels[channel].start()
        except KeyError:
            log.error('Requested to start a channel (%r) that was not previously set up.', channel)
            return False
        else:
            return True
767354
def create_channel(self, queue_name):
        
        channel = self.connection.channel()
        channel.queue_declare(queue=queue_name, durable=True)
        return channel
1362765
def _recv_flow(self, method_frame):
        '''
        
        '''
        self.channel._active = method_frame.args.read_bit()

        args = Writer()
        args.write_bit(self.channel.active)
        self.send_frame(MethodFrame(self.channel_id, 20, 21, args))

        if self._flow_control_cb is not None:
            self._flow_control_cb()
479319
def prepare(self):
        
        super(RabbitMQRequestHandler, self).prepare()
        if self._rabbitmq_is_closed:
            self._connect_to_rabbitmq()
571422
def run(self):
        
        LOGGER.debug("rabbitmq.Service.run")
        try:
            self.channel.start_consuming()
        except Exception as e:
            LOGGER.warn("rabbitmq.Service.run - Exception raised while consuming")
349672
def handle_request(request):
    
    connector = request['connector']
    hostname = connector['host']
    port = connector['port']
    virtual_host = connector['virtualHost']
    queue = connector['queue']
    user = connector['user']
    password = connector['password']
    # Establish connection with RabbitMQ server
    logging.info('Connect : [HOST=' + hostname + ', QUEUE=' + queue + ']')
    done = False
    attempts = 0
    while not done and attempts < 100:
        try:
            credentials = pika.PlainCredentials(user, password)
            con = pika.BlockingConnection(pika.ConnectionParameters(
                host=hostname,
                port=port,
                virtual_host=virtual_host,
                credentials=credentials
            ))
            channel = con.channel()
            channel.queue_declare(queue=queue, durable=True)
            req = request['request']
            logging.info('Run : [EXPERIMENT=' + req['experiment_id'] + ', RUN=' + req['run_id'] + ']')
            channel.basic_publish(
                exchange='',
                routing_key=queue,
                body=json.dumps(req),
                properties=pika.BasicProperties(
                    delivery_mode = 2, # make message persistent
                )
            )
            con.close()
            done = True
        except pika.exceptions.ConnectionClosed as ex:
            attempts += 1
            logging.exception(ex)
814805
def on_start(self):
        
        LOGGER.debug("rabbitmq.Service.on_start")
        self.connection = pika.BlockingConnection(self.parameters)
        self.channel = self.connection.channel()
        self.channel.queue_declare(queue=self.serviceQ, auto_delete=True)
        self.channel.basic_consume(self.on_request, self.serviceQ)
        self.service = threading.Thread(target=self.run, name=self.service_name)
        self.service.start()
        self.is_started = True
279303
def connect(self, host='localhost'):
        

        # Connect

        get_logger().info("Connecting to RabbitMQ server...")

        self._conn = pika.BlockingConnection(
            pika.ConnectionParameters(host=host))
        self._channel = self._conn.channel()

        # Exchanger

        get_logger().info("Declaring topic exchanger {}...".format(
            self.exchange))

        self._channel.exchange_declare(exchange=self.exchange, type='topic')

        # Create queue

        get_logger().info("Creating RabbitMQ queue...")
        result = self._channel.queue_declare(exclusive=True)

        self._queue_name = result.method.queue

        # Binding

        if self.listen_all:
            get_logger().info(
                "Binding queue to exchanger {} (listen all)...".format(
                    self.exchange
                )
            )
            self._channel.queue_bind(
                exchange=self.exchange,
                queue=self._queue_name,
                routing_key='*'
            )
        else:
            for routing_key in self.topics:
                get_logger().info(
                    "Binding queue to exchanger {} "
                    "with routing key {}...".format(
                        self.exchange, routing_key)
                )

                self._channel.queue_bind(
                    exchange=self.exchange,
                    queue=self._queue_name,
                    routing_key=routing_key
                )

        # Callback

        get_logger().info("Binding callback...")
        self._channel.basic_consume(
            self._callback, queue=self._queue_name, no_ack=True)
1111635
def open_channel(self):
        
        if self._closing:
            raise ConnectionClosed("Closed by application")
        if self.closed.done():
            raise self.closed.exception()

        channel = yield from self.channel_factory.open()
        return channel
566015
def _wait_method(self, channel_id, allowed_methods):
        
        #
        # Check the channel's deferred methods
        #
        method_queue = self.channels[channel_id].method_queue

        for queued_method in method_queue:
            method_sig = queued_method[0]
            if (allowed_methods is None) \
            or (method_sig in allowed_methods) \
            or (method_sig == (20, 40)):
                method_queue.remove(queued_method)
                return queued_method

        #
        # Nothing queued, need to wait for a method from the peer
        #
        while True:
            channel, method_sig, args, content = \
                self.method_reader.read_method()

            if (channel == channel_id) \
            and ((allowed_methods is None) \
                or (method_sig in allowed_methods) \
                or (method_sig == (20, 40))):
                return method_sig, args, content

            #
            # Certain methods like basic_return should be dispatched
            # immediately rather than being queued, even if they're not
            # one of the 'allowed_methods' we're looking for.
            #
            if (channel != 0) and (method_sig in Channel._IMMEDIATE_METHODS):
                self.channels[channel].dispatch_method(method_sig, args, content)
                continue

            #
            # Not the channel and/or method we were looking for.  Queue
            # this method for later
            #
            self.channels[channel].method_queue.append((method_sig, args, content))

            #
            # If we just queued up a method for channel 0 (the Connection
            # itself) it's probably a close method in reaction to some
            # error, so deal with it right away.
            #
            if channel == 0:
                self.wait()
913638
def _refresh_channel(self):
        '''
        
        '''
        self.channel = salt.transport.client.ReqChannel.factory(self.opts)
        return self.channel
649134
@Override
    public Broadcastable openChannel(String ccid, Integer cacheIndex, String atmosphereTrackingId) {
        throw new JoynrCommunicationException("No channels can't be opened on bounce proxy controller, only on bounce proxies.");
    }
793492
async def on_connect(self, connection):
        ""
        # NOTE: for python3, we can't pass bytestrings as keyword arguments
        # so we need to decode channel/pattern names back to str strings
        # before passing them to [p]subscribe.
        if self.channels:
            channels = {}
            for k, v in iteritems(self.channels):
                if not self.decode_responses:
                    k = k.decode(self.encoding)
                channels[k] = v
            await self.subscribe(**channels)
        if self.patterns:
            patterns = {}
            for k, v in iteritems(self.patterns):
                if not self.decode_responses:
                    k = k.decode(self.encoding)
                patterns[k] = v
            await self.psubscribe(**patterns)