Exemplo n.º 1
0
class OutgoingConnection(BaseJMSWMQConnection):
    def __init__(self, factory, out_name):
        super(OutgoingConnection, self).__init__()
        self.logger = logging.getLogger(self.__class__.__name__)
        self.jms_template = JmsTemplate(self.factory)
        
    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
Exemplo n.º 2
0
class OutgoingConnection(BaseJMSWMQConnection):
    def __init__(self, factory, name, kvdb):
        super(OutgoingConnection, self).__init__(factory, name, kvdb)
        self.jms_template = JmsTemplate(self.factory)

        # So people don't have to install PyMQI if they don't need it
        from CMQC import MQRC_UNKNOWN_OBJECT_NAME
        from pymqi import MQMIError

        self.MQMIError = MQMIError
        self.dont_reconnect_errors = (MQRC_UNKNOWN_OBJECT_NAME,)

    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)

        except Exception, e:
            if isinstance(e, self.MQMIError) and e.reason in self.dont_reconnect_errors:
                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:
                logger.warn('Caught [{}] while sending the message [{}] (reconnecting)'.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
Exemplo n.º 3
0
class OutgoingConnection(BaseJMSWMQConnection):
    def __init__(self, factory, out_name):
        super(OutgoingConnection, self).__init__(factory, out_name)
        self.logger = logging.getLogger(self.__class__.__name__)
        self.jms_template = JmsTemplate(self.factory)

        # So people don't have to install PyMQI if they don't need it
        from CMQC import MQRC_UNKNOWN_OBJECT_NAME
        from pymqi import MQMIError

        self.MQMIError = MQMIError
        self.dont_reconnect_errors = (MQRC_UNKNOWN_OBJECT_NAME, )

    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
Exemplo n.º 4
0
class OutgoingConnection(BaseJMSWMQConnection):
    def __init__(self, factory, out_name):
        super(OutgoingConnection, self).__init__(factory, out_name)
        self.logger = logging.getLogger(self.__class__.__name__)
        self.jms_template = JmsTemplate(self.factory)
        
        # So people don't have to install PyMQI if they don't need it
        from CMQC import MQRC_UNKNOWN_OBJECT_NAME
        from pymqi import MQMIError
        
        self.MQMIError = MQMIError
        self.dont_reconnect_errors = (MQRC_UNKNOWN_OBJECT_NAME, )
        
    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
Exemplo n.º 5
0
class OutgoingConnection(BaseJMSWMQConnection):
    def __init__(self, factory, name, kvdb, delivery_store):
        super(OutgoingConnection, self).__init__(factory, name, kvdb, delivery_store)
        self.logger = logging.getLogger(self.__class__.__name__)
        self.jms_template = JmsTemplate(self.factory)
        
        # So people don't have to install PyMQI if they don't need it
        from CMQC import MQRC_UNKNOWN_OBJECT_NAME
        from pymqi import MQMIError
        
        self.MQMIError = MQMIError
        self.dont_reconnect_errors = (MQRC_UNKNOWN_OBJECT_NAME,)
        
    def maybe_on_target_delivery(self, msg, start, end, target_ok, queue, inner_exc=None, needs_reconnect=None):
        if msg.get('confirm_delivery'):
            target_self_info = dumps({
                'name': self.name,
                'details': {
                    'conn_info':self.factory.get_connection_info(),
                    'queue': queue
                }
            })
            
            exc_info = {
                'inner_exc': inner_exc,
                'needs_reconnect': needs_reconnect
            }
            
            self.delivery_store.on_target_completed(
                INVOCATION_TARGET.OUTCONN_WMQ, self.name, msg, start, end, target_ok, target_self_info, exc_info)
        
    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
Exemplo n.º 6
0
class OutgoingConnection(BaseJMSWMQConnection):
    def __init__(self, factory, name, kvdb, delivery_store):
        super(OutgoingConnection, self).__init__(factory, name, kvdb, delivery_store)
        self.logger = logging.getLogger(self.__class__.__name__)
        self.jms_template = JmsTemplate(self.factory)
        
        # So people don't have to install PyMQI if they don't need it
        from CMQC import MQRC_UNKNOWN_OBJECT_NAME
        from pymqi import MQMIError
        
        self.MQMIError = MQMIError
        self.dont_reconnect_errors = (MQRC_UNKNOWN_OBJECT_NAME,)
        
    def maybe_on_target_delivery(self, msg, start, end, target_ok, queue, inner_exc=None, needs_reconnect=None):
        if msg.get('confirm_delivery'):
            target_self_info = dumps({
                'name': self.name,
                'details': {
                    'conn_info':self.factory.get_connection_info(),
                    'queue': queue
                }
            })
            
            exc_info = {
                'inner_exc': inner_exc,
                'needs_reconnect': needs_reconnect
            }
            
            self.delivery_store.on_target_completed(
                INVOCATION_TARGET.OUTCONN_WMQ, self.name, msg, start, end, target_ok, target_self_info, exc_info)
        
    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