def __init__(self, config, _requests_session=None): self.config = config self.config['timeout'] = float( self.config['timeout']) if self.config['timeout'] else 0 self.config_no_sensitive = deepcopy(self.config) self.config_no_sensitive['password'] = '******' self.requests_session = requests_session or _requests_session self.session = requests_session(pool_maxsize=self.config['pool_size']) self.https_adapter = HTTPSAdapter() self.session.mount('https://', self.https_adapter) self._component_name = get_component_name() self.default_content_type = self.get_default_content_type() self.address = None self.path_params = [] self.base_headers = {} # API keys if self.config['sec_type'] == SEC_DEF_TYPE.APIKEY: username = self.config.get('orig_username') if not username: username = self.config['username'] self.base_headers[username] = self.config['password'] self.set_address_data()
def __init__(_py_amqp_self, *args, **kwargs): super(_PyAMQPConnection, _py_amqp_self).__init__(client_properties={ 'zato.component': '{}/{}'.format(get_component_name('amqp-conn'), suffix), 'zato.version': version, 'zato.definition.name': self.config.name, }, *args, **kwargs)
def _get_engine(self, args): # SQLAlchemy import sqlalchemy # Zato from zato.common.util import api as util_api from zato.common.util.api import get_engine_url if not args.odb_type.startswith('postgresql'): connect_args = {} else: connect_args = {'application_name':util_api.get_component_name('enmasse')} return sqlalchemy.create_engine(get_engine_url(args), connect_args=connect_args)
def _get_consumer(self, _no_ack=no_ack, _gevent_sleep=sleep): """ Creates a new connection and consumer to an AMQP broker. """ # We cannot assume that we will obtain the consumer right-away. For instance, the remote end # may be currently available when we are starting. It's OK to block indefinitely (or until self.keep_running is False) # because we run in our own greenlet. consumer = None err_conn_attempts = 0 while not consumer: if not self.keep_running: break try: conn = self.config.conn_class(self.config.conn_url) consumer = _Consumer(conn, queues=self.queue, callbacks=[self._on_amqp_message], no_ack=_no_ack[self.config.ack_mode], tag_prefix='{}/{}'.format( self.config.consumer_tag_prefix, get_component_name('amqp-consumer'))) consumer.qos(prefetch_size=0, prefetch_count=self.config.prefetch_count, apply_global=False) consumer.consume() except Exception: err_conn_attempts += 1 noun = 'attempts' if err_conn_attempts > 1 else 'attempt' logger.info( 'Could not create an AMQP consumer for channel `%s` (%s %s so far), e:`%s`', self.name, err_conn_attempts, noun, format_exc()) # It's fine to sleep for a longer time because if this exception happens it means that we cannot connect # to the server at all, which will likely mean that it is down, if self.keep_running: _gevent_sleep(2) if err_conn_attempts > 0: noun = 'attempts' if err_conn_attempts > 1 else 'attempt' logger.info( 'Created an AMQP consumer for channel `%s` after %s %s', self.name, err_conn_attempts, noun) return consumer