Beispiel #1
0
    def _recv(self):
        r"""Receive a message from the buffer.

        Args:
            timeout (float, optional): Time in seconds to wait for a message.
                Defaults to self.recv_timeout.

        Returns:
            tuple (bool, str): The success or failure of receiving a message
                and the message received.

        """
        if not len(self.address):
            raise NoMessages("No messages in queue.")
        return (True, self.address.pop(0, self.empty_bytes_msg))
Beispiel #2
0
    def _recv(self):
        r"""Receive a message.

        Returns:
            tuple (bool, obj): Success or failure of receive and received
                message.

        """
        method_frame, props, msg = self.channel.basic_get(
            queue=self.queue, no_ack=False)
        if method_frame:
            self.channel.basic_ack(method_frame.delivery_tag)
        else:  # pragma: debug
            raise NoMessages("No messages in connection.")
        return (True, msg)
Beispiel #3
0
    def _recv(self, **kwargs):
        r"""Receive a message from the ZMQ socket.

        Args:
            **kwargs: Additional keyword arguments are passed to socket send.

        Returns:
            tuple (bool, obj): Success or failure of receive and received
                message.

        """
        kwargs.setdefault('flags', zmq.NOBLOCK)
        with self.socket_lock:
            try:
                if self.socket.closed:  # pragma: debug
                    self.error("Socket closed")
                    return (False, self.empty_bytes_msg)
                if self.socket_type_name == 'ROUTER':
                    [identity, total_msg] = self.socket.recv_multipart(**kwargs)
                    self._recv_identities.add(identity)
                else:
                    total_msg = self.socket.recv(**kwargs)
            except zmq.ZMQError as e:
                if e.errno == zmq.ETIMEDOUT:  # pragma: debug
                    raise NoMessages("No messages in socket.")
                elif e.errno == zmq.EAGAIN:
                    raise TemporaryCommunicationError(
                        "Socket not yet available.")
                self.special_debug(("Socket could not receive. "
                                    "(errno=%d)"), e.errno)  # pragma: debug
                raise
        # Interpret headers
        total_msg, k = self.check_reply_socket_recv(total_msg)
        if self.socket_type_name == 'SUB':
            topic, msg = total_msg.split(_flag_zmq_filter)
            assert(topic == self.topic_filter)
        else:
            msg = total_msg
        # Confirm receipt
        if k is not None:
            self._n_zmq_recv[k] += 1
        else:  # pragma: debug
            self.info("No reply address.")
        return (True, msg)