Ejemplo n.º 1
0
 def send_msg(self, msg_body, delay_sec=0):
     """
     @param msg_body:
     @return: None for send failed, otherwise return the send message id like 23F711056A4D9A94-2-151B021151D-2000013C4
     """
     #ret_flag = False
     send_msg_id = None
     message = Message(msg_body)
     message.set_delayseconds(delay_sec)
     try:
         send_msg = self.mns_queue.send_message(message)
         logger.debug("Send Message Succeed.\nMessageBody:%s\nMessageId:%s\nMessageBodyMd5:%s\n\n" % (msg_body, send_msg.message_id, send_msg.message_body_md5))
         send_msg_id = send_msg.message_id
     except MNSExceptionBase, e:
         logger.warn("Send Message Fail!\nException:%s\n\n" % e)
Ejemplo n.º 2
0
    def del_msg(self, retry=3):
        """

        @return:
        """
        num = retry
        ret_flag = False
        if self.last_recv_msg is None:
            logger.debug("last recv msg is None, nothing to do")
            return True
        while num > 0:
            try:
                self.mns_queue.delete_message(self.last_recv_msg.receipt_handle)
                logger.debug("Delete Message Succeed.\n\n")
                ret_flag = True
                self.last_recv_msg = None
                return ret_flag
            except MNSExceptionBase, e:
                logger.warn("Del Message from %s Fail!\nException:%s\n\n, retry again" % (self.mns_queue.queue_name,e))
                time.sleep(1.0)
Ejemplo n.º 3
0
 def recv_msg(self, visible_timeout=60):
     """
     @return: None means recv msg failed, otherwise, return the msg_body(means the msg that you send)
     """
     ret_flag = None
     try:
         _msg = self.mns_queue.receive_message(self.wait_seconds)
         try:
             change_msg_vis = self.mns_queue.change_message_visibility(_msg.receipt_handle, visible_timeout)
             logger.debug("Change Message Visibility Succeed!\nReceiptHandle:%s\nNextVisibleTime:%s\n\n" %
                   (change_msg_vis.receipt_handle, change_msg_vis.next_visible_time))
             ret_flag = _msg.message_body
             self.last_recv_msg = change_msg_vis
         except MNSExceptionBase, e:
             logger.warn("Change Message Visibility Fail!\nException:%s\n\n" % e)
     except MNSExceptionBase as e:
         if e.type == 'MessageNotExist':
             logger.debug("no message left in queue [%s]" %self.mns_queue.queue_name)
         else:
             logger.warn("Receive Message Fail!\nException:%s\n\n" % e)
     return ret_flag