def receive_message(self, socket): try: empty = socket.recv() assert empty == b'', 'Bad format: empty delimiter expected' reply_id = socket.recv() message_type = int(socket.recv()) message_id = socket.recv() context = socket.recv_loaded() message = socket.recv_loaded() LOG.debug( "[%(host)s] Received %(msg_type)s message %(msg_id)s", { "host": self.host, "msg_type": zmq_names.message_type_str(message_type), "msg_id": message_id }) if message_type == zmq_names.CALL_TYPE: return zmq_incoming_message.ZmqIncomingMessage( context, message, reply_id, message_id, socket, self.sender) elif message_type in zmq_names.NON_BLOCKING_TYPES: return zmq_incoming_message.ZmqIncomingMessage( context, message) else: LOG.error(_LE("Unknown message type: %s"), zmq_names.message_type_str(message_type)) except (zmq.ZMQError, AssertionError, ValueError) as e: LOG.error(_LE("Receiving message failure: %s"), str(e))
def receive_message(self, socket): try: reply_id, msg_type, message_id, context, message = \ self._receive_request(socket) LOG.debug( "[%(host)s] Received %(msg_type)s message %(msg_id)s", { "host": self.host, "msg_type": zmq_names.message_type_str(msg_type), "msg_id": message_id }) if msg_type == zmq_names.CALL_TYPE or \ msg_type in zmq_names.NON_BLOCKING_TYPES: ack_sender = self.ack_sender \ if self.conf.oslo_messaging_zmq.rpc_use_acks else None reply_sender = self.reply_sender \ if msg_type == zmq_names.CALL_TYPE else None return zmq_incoming_message.ZmqIncomingMessage( context, message, reply_id, message_id, socket, ack_sender, reply_sender) else: LOG.error(_LE("Unknown message type: %s"), zmq_names.message_type_str(msg_type)) except (zmq.ZMQError, AssertionError, ValueError) as e: LOG.error(_LE("Receiving message failed: %s"), str(e))
def receive_message(self, socket): try: context, message = self._receive_request(socket) if not message: return None return zmq_incoming_message.ZmqIncomingMessage(context, message) except (zmq.ZMQError, AssertionError) as e: LOG.error(_LE("Receiving message failed: %s"), str(e))
def _create_message(self, context, message, reply_id, message_id, socket, message_type): if message_type == zmq_names.CALL_TYPE: message = zmq_incoming_message.ZmqIncomingMessage( context, message, reply_id=reply_id, message_id=message_id, socket=socket, reply_method=self._reply) else: message = zmq_incoming_message.ZmqIncomingMessage(context, message) LOG.debug( "[%(host)s] Received %(msg_type)s message %(msg_id)s", { "host": self.host, "msg_type": zmq_names.message_type_str(message_type), "msg_id": message_id }) return message
def receive_message(self, socket): try: reply_id, msg_type, message_id, context, message = \ self._receive_request(socket) if msg_type == zmq_names.CALL_TYPE or \ msg_type in zmq_names.NON_BLOCKING_TYPES: ack_sender = self.ack_sender \ if self.conf.oslo_messaging_zmq.rpc_use_acks else None reply_sender = self.reply_sender \ if msg_type == zmq_names.CALL_TYPE else None message = zmq_incoming_message.ZmqIncomingMessage( context, message, reply_id, message_id, socket, ack_sender, reply_sender, self.messages_cache) # drop a duplicate message if message_id in self.messages_cache: LOG.warning( _LW("[%(host)s] Dropping duplicate %(msg_type)s " "message %(msg_id)s"), { "host": self.host, "msg_type": zmq_names.message_type_str(msg_type), "msg_id": message_id }) # NOTE(gdavoian): send yet another ack for the non-CALL # message, since the old one might be lost; # for the CALL message also try to resend its reply # (of course, if it was already obtained and cached). message._acknowledge() if msg_type == zmq_names.CALL_TYPE: message._reply_from_cache() return None self.messages_cache.add(message_id) LOG.debug( "[%(host)s] Received %(msg_type)s message %(msg_id)s", { "host": self.host, "msg_type": zmq_names.message_type_str(msg_type), "msg_id": message_id }) # NOTE(gdavoian): send an immediate ack, since it may # be too late to wait until the message will be # dispatched and processed by a RPC server message._acknowledge() return message else: LOG.error(_LE("Unknown message type: %s"), zmq_names.message_type_str(msg_type)) except (zmq.ZMQError, AssertionError, ValueError) as e: LOG.error(_LE("Receiving message failure: %s"), str(e))
def receive_request(self, socket): try: topic_filter = socket.recv() message_version = socket.recv_string() receive_request_version = \ self._get_receive_request_version(message_version) context, message = receive_request_version(topic_filter, socket) return zmq_incoming_message.ZmqIncomingMessage(context, message) except (zmq.ZMQError, AssertionError, ValueError, zmq_version.UnsupportedMessageVersionError) as e: LOG.error(_LE("Receiving message failed: %s"), str(e)) # NOTE(gdavoian): drop the left parts of a broken message if socket.getsockopt(zmq.RCVMORE): socket.recv_multipart()