Exemple #1
0
 def send(self, msg, default_delivery_mode, default_expiration, default_priority, default_max_chars_printed):
     
     jms_msg = TextMessage()
     
     # Common named arguments first
     jms_msg.text = msg.get('body')
     jms_msg.jms_expiration = int(msg.get('expiration') or default_expiration)
     jms_msg.jms_delivery_mode = msg.get('delivery_mode') or default_delivery_mode
     jms_msg.jms_priority = msg.get('priority') or default_priority
     jms_msg.max_chars_printed = msg.get('max_chars_printed') or default_max_chars_printed
     
     kwargs = msg.get('kwargs')
     
     # JMS-specific ones now
     jms_msg.jms_destination = kwargs.get('jms_destination')
     jms_msg.jms_correlation_id = str(kwargs.get('jms_correlation_id'))
     jms_msg.jms_message_id = str(kwargs.get('jms_message_id'))
     jms_msg.jms_redelivered = kwargs.get('jms_redelivered')
     jms_msg.jms_timestamp = kwargs.get('jms_timestamp')
     
     queue = str(msg['queue'])
     
     try:
         start = datetime.utcnow()
         self.jms_template.send(jms_msg, queue)
         self.maybe_on_target_delivery(msg, start, datetime.utcnow(), True, queue)
             
     except Exception, e:
         if isinstance(e, self.MQMIError) and e.reason in self.dont_reconnect_errors:
             self.logger.warn(
                 'Caught [{}/{}] while sending the message [{}] (not reconnecting)'.format(e.reason, e.errorAsString(), jms_msg))
             self.maybe_on_target_delivery(msg, start, datetime.utcnow(), False, queue, format_exc(e), False)
             
         else:
             self.logger.warn('Caught [{}] while sending the message [{}] (reconnecting)'.format(format_exc(e), jms_msg))
             self.maybe_on_target_delivery(msg, start, datetime.utcnow(), False, queue, format_exc(e), True)
             
             if self._keep_connecting(e):
                 self.close()
                 self.keep_connecting = True
                 self.factory._disconnecting = False
                 self.start()
             else:
                 raise
Exemple #2
0
 def send(self, msg, default_delivery_mode, default_expiration, default_priority, default_max_chars_printed):
     
     jms_msg = TextMessage()
     
     # Common named arguments first
     jms_msg.text = msg.get('body')
     jms_msg.jms_expiration = int(msg.get('expiration') or default_expiration)
     jms_msg.jms_delivery_mode = msg.get('delivery_mode') or default_delivery_mode
     jms_msg.jms_priority = msg.get('priority') or default_priority
     jms_msg.max_chars_printed = msg.get('max_chars_printed') or default_max_chars_printed
     
     kwargs = msg.get('kwargs')
     
     # JMS-specific ones now
     jms_msg.jms_destination = kwargs.get('jms_destination')
     jms_msg.jms_correlation_id = str(kwargs.get('jms_correlation_id'))
     jms_msg.jms_message_id = str(kwargs.get('jms_message_id'))
     jms_msg.jms_redelivered = kwargs.get('jms_redelivered')
     jms_msg.jms_timestamp = kwargs.get('jms_timestamp')
     
     queue = str(msg['queue'])
     
     try:
         start = datetime.utcnow()
         self.jms_template.send(jms_msg, queue)
         self.maybe_on_target_delivery(msg, start, datetime.utcnow(), True, queue)
             
     except Exception, e:
         if isinstance(e, self.MQMIError) and e.reason in self.dont_reconnect_errors:
             self.logger.warn(
                 'Caught [{}/{}] while sending the message [{}] (not reconnecting)'.format(e.reason, e.errorAsString(), jms_msg))
             self.maybe_on_target_delivery(msg, start, datetime.utcnow(), False, queue, format_exc(e), False)
             
         else:
             self.logger.warn('Caught [{}] while sending the message [{}] (reconnecting)'.format(format_exc(e), jms_msg))
             self.maybe_on_target_delivery(msg, start, datetime.utcnow(), False, queue, format_exc(e), True)
             
             if self._keep_connecting(e):
                 self.close()
                 self.keep_connecting = True
                 self.factory._disconnecting = False
                 self.start()
             else:
                 raise
Exemple #3
0
 def send(self, msg, default_delivery_mode, default_expiration, default_priority, default_max_chars_printed):
     jms_msg = TextMessage()
     jms_msg.text = msg.get('body')
     jms_msg.jms_correlation_id = msg.get('jms_correlation_id')
     jms_msg.jms_delivery_mode = msg.get('jms_delivery_mode') or default_delivery_mode
     jms_msg.jms_destination = msg.get('jms_destination')
     jms_msg.jms_expiration = msg.get('jms_expiration') or default_expiration
     jms_msg.jms_message_id = msg.get('jms_message_id')
     jms_msg.jms_priority = msg.get('jms_priority') or default_priority
     jms_msg.jms_redelivered = msg.get('jms_redelivered')
     jms_msg.jms_timestamp = msg.get('jms_timestamp')
     jms_msg.max_chars_printed = msg.get('max_chars_printed') or default_max_chars_printed
     
     queue = str(msg['queue'])
     
     try:
         self.jms_template.send(jms_msg, queue)
     except Exception, e:
         if self._keep_connecting(e):
             self.close()
             self.keep_connecting = True
             self.factory._disconnecting = False
             self.start()
         else:
             raise
Exemple #4
0
    def _build_text_message(self, md, message):
        self.logger.log(TRACE1, "Building a text message [%r], md [%r]" % (repr(message), repr(md)))

        mqrfh2 = MQRFH2JMS(self.needs_mcd)
        mqrfh2.build_folders_and_payload_from_message(message)

        jms_folder = mqrfh2.folders.get("jms", None)
        mcd_folder = mqrfh2.folders.get("mcd", None)
        usr_folder = mqrfh2.folders.get("usr", None)

        # Create a message instance ..
        text_message = TextMessage()

        if usr_folder:
            for attr_name, attr_value in usr_folder.items():
                setattr(text_message, attr_name, str(attr_value))

        # .. set its JMS properties ..

        if jms_folder:
            if jms_folder.find("Dst") is not None:
                text_message.jms_destination = jms_folder.find("Dst").text.strip()

            if jms_folder.find("Exp") is not None:
                text_message.jms_expiration = long(jms_folder.find("Exp").text)
            else:
                text_message.jms_expiration = 0 # Same as in Java

            if jms_folder.find("Cid") is not None:
                text_message.jms_correlation_id = jms_folder.find("Cid").text

        if md.Persistence == self.CMQC.MQPER_NOT_PERSISTENT:
            text_message.jms_delivery_mode = DELIVERY_MODE_NON_PERSISTENT
        elif md.Persistence in(self.CMQC.MQPER_PERSISTENT, self.CMQC.MQPER_PERSISTENCE_AS_Q_DEF):
            text_message.jms_delivery_mode = DELIVERY_MODE_PERSISTENT
        else:
            text = "Don't know how to handle md.Persistence mode [%s]" % (md.Persistence)
            self.logger.error(text)
            exc = WebSphereMQJMSException(text)
            raise exc

        if md.ReplyToQ.strip():
            self.logger.log(TRACE1, "Found md.ReplyToQ=[%r]" % md.ReplyToQ)
            text_message.jms_reply_to = "queue://" + md.ReplyToQMgr.strip() + "/" + md.ReplyToQ.strip()

        text_message.jms_priority = md.Priority
        text_message.jms_message_id = _WMQ_ID_PREFIX + hexlify(md.MsgId)
        text_message.jms_timestamp = self._get_jms_timestamp_from_md(md.PutDate.strip(), md.PutTime.strip())
        text_message.jms_redelivered = bool(int(md.BackoutCount))

        text_message.JMSXUserID = md.UserIdentifier.strip()
        text_message.JMSXAppID = md.PutApplName.strip()
        text_message.JMSXDeliveryCount = md.BackoutCount
        text_message.JMSXGroupID = md.GroupId.strip()
        text_message.JMSXGroupSeq = md.MsgSeqNumber

        md_report_to_jms = {
            self.CMQC.MQRO_EXCEPTION: "Exception",
            self.CMQC.MQRO_EXPIRATION: "Expiration",
            self.CMQC.MQRO_COA: "COA",
            self.CMQC.MQRO_COD: "COD",
            self.CMQC.MQRO_PAN: "PAN",
            self.CMQC.MQRO_NAN: "NAN",
            self.CMQC.MQRO_PASS_MSG_ID: "Pass_Msg_ID",
            self.CMQC.MQRO_PASS_CORREL_ID: "Pass_Correl_ID",
            self.CMQC.MQRO_DISCARD_MSG: "Discard_Msg",
        }

        for report_name, jms_header_name in md_report_to_jms.iteritems():
            report_value = md.Report & report_name
            if report_value:
                header_value = report_value
            else:
                header_value = None

            setattr(text_message, "JMS_IBM_Report_" + jms_header_name, header_value)

        text_message.JMS_IBM_MsgType = md.MsgType
        text_message.JMS_IBM_Feedback = md.Feedback
        text_message.JMS_IBM_Format = md.Format.strip()
        text_message.JMS_IBM_PutApplType = md.PutApplType
        text_message.JMS_IBM_PutDate = md.PutDate.strip()
        text_message.JMS_IBM_PutTime = md.PutTime.strip()

        if md.MsgFlags & self.CMQC.MQMF_LAST_MSG_IN_GROUP:
            text_message.JMS_IBM_Last_Msg_In_Group = self.CMQC.MQMF_LAST_MSG_IN_GROUP
        else:
            text_message.JMS_IBM_Last_Msg_In_Group = None

        # .. and its payload too.
        if mqrfh2.payload:
            text_message.text = mqrfh2.payload

        return text_message
Exemple #5
0
    def _build_text_message(self, md, message):
        self.logger.log(TRACE1, "Building a text message [%r], md [%r]" % (repr(message), repr(md)))

        mqrfh2 = MQRFH2JMS()
        mqrfh2.build_folders_and_payload_from_message(message)

        jms_folder = mqrfh2.folders.get("jms", None)
        mcd_folder = mqrfh2.folders.get("mcd", None)
        usr_folder = mqrfh2.folders.get("usr", None)

        # Create a message instance ..
        text_message = TextMessage()

        if usr_folder:
            for attr_name, attr_value in usr_folder.items():
                setattr(text_message, attr_name, str(attr_value))

        # .. set its JMS properties ..

        if jms_folder:
            if jms_folder.find("Dst") is not None:
                text_message.jms_destination = jms_folder.find("Dst").text.strip()

            if jms_folder.find("Exp") is not None:
                text_message.jms_expiration = long(jms_folder.find("Exp").text)
            else:
                text_message.jms_expiration = 0 # Same as in Java

            if jms_folder.find("Cid") is not None:
                text_message.jms_correlation_id = jms_folder.find("Cid").text

        if md.Persistence == self.CMQC.MQPER_NOT_PERSISTENT:
            text_message.jms_delivery_mode = DELIVERY_MODE_NON_PERSISTENT
        elif md.Persistence in(self.CMQC.MQPER_PERSISTENT, self.CMQC.MQPER_PERSISTENCE_AS_Q_DEF):
            text_message.jms_delivery_mode = DELIVERY_MODE_PERSISTENT
        else:
            text = "Don't know how to handle md.Persistence mode [%s]" % (md.Persistence)
            self.logger.error(text)
            exc = WebSphereMQJMSException(text)
            raise exc

        if md.ReplyToQ.strip():
            self.logger.log(TRACE1, "Found md.ReplyToQ=[%r]" % md.ReplyToQ)
            text_message.jms_reply_to = "queue://" + md.ReplyToQMgr.strip() + "/" + md.ReplyToQ.strip()

        text_message.jms_priority = md.Priority
        text_message.jms_message_id = _WMQ_ID_PREFIX + hexlify(md.MsgId)
        text_message.jms_timestamp = self._get_jms_timestamp_from_md(md.PutDate.strip(), md.PutTime.strip())
        text_message.jms_redelivered = bool(int(md.BackoutCount))

        text_message.JMSXUserID = md.UserIdentifier.strip()
        text_message.JMSXAppID = md.PutApplName.strip()
        text_message.JMSXDeliveryCount = md.BackoutCount
        text_message.JMSXGroupID = md.GroupId.strip()
        text_message.JMSXGroupSeq = md.MsgSeqNumber

        md_report_to_jms = {
            self.CMQC.MQRO_EXCEPTION: "Exception",
            self.CMQC.MQRO_EXPIRATION: "Expiration",
            self.CMQC.MQRO_COA: "COA",
            self.CMQC.MQRO_COD: "COD",
            self.CMQC.MQRO_PAN: "PAN",
            self.CMQC.MQRO_NAN: "NAN",
            self.CMQC.MQRO_PASS_MSG_ID: "Pass_Msg_ID",
            self.CMQC.MQRO_PASS_CORREL_ID: "Pass_Correl_ID",
            self.CMQC.MQRO_DISCARD_MSG: "Discard_Msg",
        }

        for report_name, jms_header_name in md_report_to_jms.iteritems():
            report_value = md.Report & report_name
            if report_value:
                header_value = report_value
            else:
                header_value = None

            setattr(text_message, "JMS_IBM_Report_" + jms_header_name, header_value)

        text_message.JMS_IBM_MsgType = md.MsgType
        text_message.JMS_IBM_Feedback = md.Feedback
        text_message.JMS_IBM_Format = md.Format.strip()
        text_message.JMS_IBM_PutApplType = md.PutApplType
        text_message.JMS_IBM_PutDate = md.PutDate.strip()
        text_message.JMS_IBM_PutTime = md.PutTime.strip()

        if md.MsgFlags & self.CMQC.MQMF_LAST_MSG_IN_GROUP:
            text_message.JMS_IBM_Last_Msg_In_Group = self.CMQC.MQMF_LAST_MSG_IN_GROUP
        else:
            text_message.JMS_IBM_Last_Msg_In_Group = None

        # .. and its payload too.
        if mqrfh2.payload:
            text_message.text = mqrfh2.payload

        return text_message
Exemple #6
0
    def send(self, msg, default_delivery_mode, default_expiration,
             default_priority, default_max_chars_printed):
        jms_msg = TextMessage()
        jms_msg.text = msg.get('body')
        jms_msg.jms_correlation_id = msg.get('jms_correlation_id')
        jms_msg.jms_delivery_mode = msg.get(
            'jms_delivery_mode') or default_delivery_mode
        jms_msg.jms_destination = msg.get('jms_destination')
        jms_msg.jms_expiration = int(
            msg.get('jms_expiration') or default_expiration)
        jms_msg.jms_message_id = msg.get('jms_message_id')
        jms_msg.jms_priority = msg.get('jms_priority') or default_priority
        jms_msg.jms_redelivered = msg.get('jms_redelivered')
        jms_msg.jms_timestamp = msg.get('jms_timestamp')
        jms_msg.max_chars_printed = msg.get(
            'max_chars_printed') or default_max_chars_printed

        queue = str(msg['queue'])

        try:
            self.jms_template.send(jms_msg, queue)
        except Exception, e:

            if isinstance(
                    e,
                    self.MQMIError) and e.reason in self.dont_reconnect_errors:
                self.logger.warn(
                    'Caught [{}/{}] while sending the message [{}]'.format(
                        e.reason, e.errorAsString(), jms_msg))
            else:
                self.logger.warn(
                    'Caught [{}] while sending the message [{}]'.format(
                        format_exc(e), jms_msg))

                if self._keep_connecting(e):
                    self.close()
                    self.keep_connecting = True
                    self.factory._disconnecting = False
                    self.start()
                else:
                    raise
Exemple #7
0
 def send(self, msg, default_delivery_mode, default_expiration, default_priority, default_max_chars_printed):
     jms_msg = TextMessage()
     jms_msg.text = msg.get('body')
     jms_msg.jms_correlation_id = msg.get('jms_correlation_id')
     jms_msg.jms_delivery_mode = msg.get('jms_delivery_mode') or default_delivery_mode
     jms_msg.jms_destination = msg.get('jms_destination')
     jms_msg.jms_expiration = int(msg.get('jms_expiration') or default_expiration)
     jms_msg.jms_message_id = msg.get('jms_message_id')
     jms_msg.jms_priority = msg.get('jms_priority') or default_priority
     jms_msg.jms_redelivered = msg.get('jms_redelivered')
     jms_msg.jms_timestamp = msg.get('jms_timestamp')
     jms_msg.max_chars_printed = msg.get('max_chars_printed') or default_max_chars_printed
     
     queue = str(msg['queue'])
     
     try:
         self.jms_template.send(jms_msg, queue)
     except Exception, e:
         
         if isinstance(e, self.MQMIError) and e.reason in self.dont_reconnect_errors:
             self.logger.warn('Caught [{}/{}] while sending the message [{}]'.format(e.reason, e.errorAsString(), jms_msg))
         else:
             self.logger.warn('Caught [{}] while sending the message [{}]'.format(format_exc(e), jms_msg))
             
             if self._keep_connecting(e):
                 self.close()
                 self.keep_connecting = True
                 self.factory._disconnecting = False
                 self.start()
             else:
                 raise