当前位置: 首页>>代码示例>>Python>>正文


Python pika.URLParameters方法代码示例

本文整理汇总了Python中pika.URLParameters方法的典型用法代码示例。如果您正苦于以下问题:Python pika.URLParameters方法的具体用法?Python pika.URLParameters怎么用?Python pika.URLParameters使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pika的用法示例。


在下文中一共展示了pika.URLParameters方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_rabbitmq_resources

# 需要导入模块: import pika [as 别名]
# 或者: from pika import URLParameters [as 别名]
def create_rabbitmq_resources(rabbit_amqp_url, executor_id, job_id):
    """
    Creates RabbitMQ queues and exchanges of a given job in a thread.
    Called when a job is created.
    """
    logger.debug('ExecutorID {} | JobID {} - Creating RabbitMQ resources'.format(executor_id, job_id))

    def create_resources(rabbit_amqp_url, executor_id, job_id):
        exchange = 'pywren-{}-{}'.format(executor_id, job_id)
        queue_0 = '{}-0'.format(exchange)  # For waiting
        queue_1 = '{}-1'.format(exchange)  # For invoker

        params = pika.URLParameters(rabbit_amqp_url)
        connection = pika.BlockingConnection(params)
        channel = connection.channel()
        channel.exchange_declare(exchange=exchange, exchange_type='fanout', auto_delete=True)
        channel.queue_declare(queue=queue_0, auto_delete=True)
        channel.queue_bind(exchange=exchange, queue=queue_0)
        channel.queue_declare(queue=queue_1, auto_delete=True)
        channel.queue_bind(exchange=exchange, queue=queue_1)
        connection.close()

    th = threading.Thread(target=create_resources, args=(rabbit_amqp_url, executor_id, job_id))
    th.daemon = True
    th.start() 
开发者ID:pywren,项目名称:pywren-ibm-cloud,代码行数:27,代码来源:utils.py

示例2: delete_rabbitmq_resources

# 需要导入模块: import pika [as 别名]
# 或者: from pika import URLParameters [as 别名]
def delete_rabbitmq_resources(rabbit_amqp_url, executor_id, job_id):
    """
    Deletes RabbitMQ queues and exchanges of a given job.
    Only called when an exception is produced, otherwise resources are
    automatically deleted.
    """
    exchange = 'pywren-{}-{}'.format(executor_id, job_id)
    queue_0 = '{}-0'.format(exchange)  # For waiting
    queue_1 = '{}-1'.format(exchange)  # For invoker

    params = pika.URLParameters(rabbit_amqp_url)
    connection = pika.BlockingConnection(params)
    channel = connection.channel()
    channel.queue_delete(queue=queue_0)
    channel.queue_delete(queue=queue_1)
    channel.exchange_delete(exchange=exchange)
    connection.close() 
开发者ID:pywren,项目名称:pywren-ibm-cloud,代码行数:19,代码来源:utils.py

示例3: _job_monitor_thread

# 需要导入模块: import pika [as 别名]
# 或者: from pika import URLParameters [as 别名]
def _job_monitor_thread(job_key, total_calls, rabbit_amqp_url, job_monitor_q):
    executor_id, job_id = job_key.rsplit('-', 1)
    exchange = 'pywren-{}-{}'.format(executor_id, job_id)
    queue_0 = '{}-0'.format(exchange)
    total_calls_rcvd = 0

    def callback(ch, method, properties, body):
        nonlocal total_calls_rcvd
        call_status = json.loads(body.decode("utf-8"))
        job_monitor_q.put(call_status)
        if call_status['type'] == '__end__':
            total_calls_rcvd += 1
        if total_calls_rcvd == total_calls:
            ch.stop_consuming()

    logger.debug('ExecutorID {} | JobID {} - Consuming from RabbitMQ '
                 'queue'.format(executor_id, job_id))
    params = pika.URLParameters(rabbit_amqp_url)
    connection = pika.BlockingConnection(params)
    channel = connection.channel()
    channel.basic_consume(callback, queue=queue_0, no_ack=True)
    channel.start_consuming() 
开发者ID:pywren,项目名称:pywren-ibm-cloud,代码行数:24,代码来源:wait_rabbitmq.py

示例4: run

# 需要导入模块: import pika [as 别名]
# 或者: from pika import URLParameters [as 别名]
def run(self):
        while True:
            try:
                # Connect the broker
                self.pika_connection = pika.BlockingConnection(
                    pika.URLParameters(self.uri)
                )
                self.channel = self.pika_connection.channel()
                self.channel.basic_consume(
                    queue=self.queue_name, on_message_callback=self._process_message
                )
                self.channel.start_consuming()
            except (KeyboardInterrupt, SystemExit):
                self.helper.log_info("Connector stop")
                exit(0)
            except Exception as e:
                self.helper.log_error(str(e))
                time.sleep(10) 
开发者ID:OpenCTI-Platform,项目名称:client-python,代码行数:20,代码来源:opencti_connector_helper.py

示例5: _send_status_rabbitmq

# 需要导入模块: import pika [as 别名]
# 或者: from pika import URLParameters [as 别名]
def _send_status_rabbitmq(self):
        """
        Send the status event to RabbitMQ
        """
        dmpd_response_status = json.dumps(self.response)
        drs = sizeof_fmt(len(dmpd_response_status))

        executor_id = self.response['executor_id']
        job_id = self.response['job_id']

        rabbit_amqp_url = self.config['rabbitmq'].get('amqp_url')
        status_sent = False
        output_query_count = 0
        params = pika.URLParameters(rabbit_amqp_url)
        exchange = 'pywren-{}-{}'.format(executor_id, job_id)

        while not status_sent and output_query_count < 5:
            output_query_count = output_query_count + 1
            try:
                connection = pika.BlockingConnection(params)
                channel = connection.channel()
                channel.exchange_declare(exchange=exchange, exchange_type='fanout', auto_delete=True)
                channel.basic_publish(exchange=exchange, routing_key='',
                                      body=dmpd_response_status)
                connection.close()
                logger.info("Execution status sent to rabbitmq - Size: {}".format(drs))
                status_sent = True
            except Exception as e:
                logger.error("Unable to send status to rabbitmq")
                logger.error(str(e))
                logger.info('Retrying to send status to rabbitmq...')
                time.sleep(0.2) 
开发者ID:pywren,项目名称:pywren-ibm-cloud,代码行数:34,代码来源:handler.py

示例6: _fill_optional_args

# 需要导入模块: import pika [as 别名]
# 或者: from pika import URLParameters [as 别名]
def _fill_optional_args(self, function, data):
        """
        Fills in those reserved, optional parameters that might be write to the function signature
        """
        func_sig = inspect.signature(function)

        if 'ibm_cos' in func_sig.parameters:
            if 'ibm_cos' in self.pywren_config:
                if self.internal_storage.backend == 'ibm_cos':
                    ibm_boto3_client = self.internal_storage.get_client()
                else:
                    ibm_boto3_client = Storage(self.pywren_config, 'ibm_cos').get_client()
                data['ibm_cos'] = ibm_boto3_client
            else:
                raise Exception('Cannot create the ibm_cos client: missing configuration')

        if 'storage' in func_sig.parameters:
            data['storage'] = self.internal_storage.get_client()

        if 'rabbitmq' in func_sig.parameters:
            if 'rabbitmq' in self.pywren_config:
                rabbit_amqp_url = self.pywren_config['rabbitmq'].get('amqp_url')
                params = pika.URLParameters(rabbit_amqp_url)
                connection = pika.BlockingConnection(params)
                data['rabbitmq'] = connection
            else:
                raise Exception('Cannot create the rabbitmq client: missing configuration')

        if 'id' in func_sig.parameters:
            data['id'] = int(self.call_id) 
开发者ID:pywren,项目名称:pywren-ibm-cloud,代码行数:32,代码来源:jobrunner.py

示例7: __handle_queue_message

# 需要导入模块: import pika [as 别名]
# 或者: from pika import URLParameters [as 别名]
def __handle_queue_message(self, requests_timeout: int):
        """
        Метод отвечает за подключение к RabbitMQ очереди и ожидания сообщения с нужным `task_id`
        :param requests_timeout: Время между запросами к серверу.
        """
        # кол-во попыток на получение результата
        attempts = 20

        # подключаемся к RabbitMQ и устанавливаем осединение + канал
        parameters = pika.URLParameters(
            f"amqp://{self.rtmq_username}:{self.rtmq_password}@{self.rtmq_host}:{self.rtmq_port}/{self.rtmq_vhost}"
        )
        connection = pika.BlockingConnection(parameters=parameters)
        channel = connection.channel()

        while attempts > 0:
            # получение сообщения из очереди
            method_frame, _, body = channel.basic_get(self.queue_name)
            if body:
                # декодируем сообщение из bytes в JSON
                json_body = json.loads(body.decode())

                # если ID задания сообщения из очереди совпадает с ID требуемого задания - возвращаем его.
                # если ID не совпадают - ожидаем дальше
                if int(json_body.get("taskId")) == self.task_id:
                    channel.basic_ack(method_frame.delivery_tag)
                    connection.close()
                    return json_body
            # ставим небольшую задержку что бы не спамить сервер rabbitmq
            time.sleep(requests_timeout)
            # уменьшаем счётчик попыток
            attempts -= 1

        return False 
开发者ID:AndreiDrang,项目名称:python3-anticaptcha,代码行数:36,代码来源:CallbackClient.py

示例8: connect

# 需要导入模块: import pika [as 别名]
# 或者: from pika import URLParameters [as 别名]
def connect(self):
        self.connected_node = self.broker_manager.get_current_node(self.publisher_id)
        ip = self.broker_manager.get_node_ip(self.connected_node)
        port = self.broker_manager.get_publisher_port(self.connected_node)
        self.set_actor()
        console_out(f"Attempting to connect to {self.connected_node} {ip}:{port}", self.get_actor())
        parameters = pika.URLParameters(f"amqp://jack:jack@{ip}:{port}/%2F")
        return pika.SelectConnection(parameters,
                                     on_open_callback=self.on_connection_open,
                                     on_open_error_callback=self.on_connection_open_error,
                                     on_close_callback=self.on_connection_closed) 
开发者ID:Vanlightly,项目名称:ChaosTestingCode,代码行数:13,代码来源:RabbitPublisher.py

示例9: connect

# 需要导入模块: import pika [as 别名]
# 或者: from pika import URLParameters [as 别名]
def connect():
    global connection, curr_node, terminate
    print("Attempting to connect to " + nodes[curr_node])
    parameters = pika.URLParameters('amqp://jack:jack@' + nodes[curr_node] + ':5672/%2F')
    connection = pika.SelectConnection(parameters=parameters,
                                on_open_callback=on_open,
                                on_open_error_callback=reconnect,
                                on_close_callback=on_close)

    try:
        connection.ioloop.start()
    except KeyboardInterrupt:
        connection.close()
        connection.ioloop.stop()
        terminate = True 
开发者ID:Vanlightly,项目名称:ChaosTestingCode,代码行数:17,代码来源:send-with-confirm.py

示例10: mq_connect

# 需要导入模块: import pika [as 别名]
# 或者: from pika import URLParameters [as 别名]
def mq_connect():
    """ Connects to the MQ and returns the connection """
    _url = create_mq_url(options.mq_hostname, options.mq_port,
                         username=options.mq_username,
                         password=options.mq_password)
    parameters = pika.URLParameters(_url)
    connection = pika.BlockingConnection(parameters)
    return connection 
开发者ID:BishopFox,项目名称:SpoofcheckSelfTest,代码行数:10,代码来源:mq.py

示例11: connect

# 需要导入模块: import pika [as 别名]
# 或者: from pika import URLParameters [as 别名]
def connect(self, *args, **kwargs):
        """
        This method connects to RabbitMQ, returning the connection handle.
        When the connection is established, the on_connection_open method
        will be invoked by pika.
        :rtype: pika.SelectConnection
        """
        LOGGER.debug('Connecting to %s', self._url)
        LOGGER.debug('Got arguments: %r %r', args, kwargs)
        conn = adapters.TornadoConnection(pika.URLParameters(self._url),
                                          self.on_connection_open)
        self._connection = conn
        return conn 
开发者ID:BishopFox,项目名称:SpoofcheckSelfTest,代码行数:15,代码来源:event_consumers.py

示例12: connect

# 需要导入模块: import pika [as 别名]
# 或者: from pika import URLParameters [as 别名]
def connect():
    params = pika.URLParameters(RMQ_URI)
    connection = pika.BlockingConnection(params)
    channel = connection.channel()
    channel.basic_qos(prefetch_count=1)
    channel.queue_declare(queue=RMQ_QUEUE, durable=True)
    channel.exchange_declare(exchange=RMQ_XCHNG, exchange_type='topic', durable=True)
    channel.queue_bind(queue=RMQ_QUEUE, exchange=RMQ_XCHNG, routing_key=RMQ_QUEUE)
    return channel 
开发者ID:terraref,项目名称:computing-pipeline,代码行数:11,代码来源:terra_compressor_queue.py

示例13: connect

# 需要导入模块: import pika [as 别名]
# 或者: from pika import URLParameters [as 别名]
def connect():
    params = pika.URLParameters(RMQ_URI+"?heartbeat_interval=300")
    connection = pika.BlockingConnection(params)
    channel = connection.channel()
    channel.basic_qos(prefetch_count=1)
    channel.queue_declare(queue=RMQ_QUEUE, durable=True)
    channel.exchange_declare(exchange=RMQ_XCHNG, exchange_type='topic', durable=True)
    channel.queue_bind(queue=RMQ_QUEUE, exchange=RMQ_XCHNG, routing_key=RMQ_QUEUE)
    return channel 
开发者ID:terraref,项目名称:computing-pipeline,代码行数:11,代码来源:terra_compressor.py

示例14: _parse_url

# 需要导入模块: import pika [as 别名]
# 或者: from pika import URLParameters [as 别名]
def _parse_url(broker_url):
    params = pika.URLParameters(broker_url)
    return params.host 
开发者ID:cloudify-cosmo,项目名称:cloudify-plugins-common,代码行数:5,代码来源:cluster.py

示例15: __init__

# 需要导入模块: import pika [as 别名]
# 或者: from pika import URLParameters [as 别名]
def __init__(self, url, routing_key):
        self.parameters = pika.URLParameters(url)
        self.client = None
        self.queued_messages = []
        self.routing_key = routing_key 
开发者ID:smartbgp,项目名称:yabmp,代码行数:7,代码来源:factory.py


注:本文中的pika.URLParameters方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。