Пример #1
0
    def __init__(self, url=None):
        """Create a new instance of the Connection object"""
        super(Connection, self).__init__()

        # Create a name for the connection
        self._name = '0x%x' % id(self)

        # Extract parts of connection URL for use later
        self._args = self._process_url(url or self.DEFAULT_URL)

        # General events and queues shared across threads
        self._events = events.Events()

        # A queue for the child threads to put exceptions in
        self._exceptions = queue.Queue()

        # One queue for writing frames, regardless of the channel sending them
        self._write_queue = queue.Queue()

        # Lock used when managing the channel stack
        self._channel_lock = threading.Lock()

        # Attributes for core object threads
        self._channel0 = None
        self._channels = dict()
        self._heartbeat_checker = None
        self._io = None

        # Used by Message for breaking up body frames
        self._max_frame_size = None

        # Connect to RabbitMQ
        self._connect()
Пример #2
0
    def channel(self, blocking_read=False):
        """Create a new channel

        If blocking_read is True, the cross-thread Queue.get use will use
        blocking operations that lower resource utilization and increase
        throughput. However, due to how Python's blocking Queue.get is
        implemented, KeyboardInterrupt is not raised when CTRL-C is
        pressed.

        :param bool blocking_read: Enable for higher throughput
        :raises: rabbitpy.exceptions.AMQPException
        :raises: rabbitpy.exceptions.RemoteClosedChannelException

        """
        with self._channel_lock:
            channel_id = self._get_next_channel_id()
            channel_frames = queue.Queue()
            self._channels[channel_id] = \
                channel.Channel(channel_id,
                                self.capabilities,
                                self._events,
                                self._exceptions,
                                channel_frames,
                                self._write_queue,
                                self._max_frame_size,
                                self._io.write_trigger,
                                blocking_read)
            self._add_channel_to_io(self._channels[channel_id], channel_frames)
            self._channels[channel_id].open()
            return self._channels[channel_id]
Пример #3
0
 def __init__(self, connection_args, events_obj, exception_queue,
              write_queue, write_trigger, connection):
     super(Channel0, self).__init__(exception_queue, write_trigger,
                                    connection)
     self._channel_id = 0
     self._args = connection_args
     self._events = events_obj
     self._exceptions = exception_queue
     self._read_queue = queue.Queue()
     self._write_queue = write_queue
     self._write_trigger = write_trigger
     self._state = self.CLOSED
     self._max_channels = connection_args['channel_max']
     self._max_frame_size = connection_args['frame_max']
     self._heartbeat_interval = connection_args['heartbeat']
     self.properties = None