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


Python pika.SelectConnection方法代码示例

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


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

示例1: connect

# 需要导入模块: import pika [as 别名]
# 或者: from pika import SelectConnection [as 别名]
def connect(self):
        """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

        """
        self.logger.info('Connecting to %s', self._prefix)
        account = 'opensuse'
        server = 'rabbit.opensuse.org'
        if self._prefix == 'suse':
            account = 'suse'
            server = 'rabbit.suse.de'
        credentials = pika.PlainCredentials(account, account)
        context = ssl.create_default_context()
        ssl_options = pika.SSLOptions(context, server)
        parameters = pika.ConnectionParameters(server, 5671, '/', credentials, ssl_options=ssl_options, socket_timeout=10)
        return pika.SelectConnection(parameters,
                                     on_open_callback=self.on_connection_open) 
开发者ID:openSUSE,项目名称:openSUSE-release-tools,代码行数:22,代码来源:PubSubConsumer.py

示例2: connect

# 需要导入模块: import pika [as 别名]
# 或者: from pika import SelectConnection [as 别名]
def connect(self):
        """
        From pika docs:

        This method connects to RabbitMQ, returning the connection handle.
        When the connection is established, the on_connection_open method
        will be invoked by pika.

        Returns:
            pika.SelectConnection
        """
        LOGGER.info('Connecting to %s', ascii_str(self._conn_params_dict['host']))
        if self.input_queue is not None or self.output_queue is not None:
            self._amqp_setup_timeout_callback_manager.deactivate()
            self._amqp_setup_timeout_callback_manager.activate()
        return pika.SelectConnection(
                pika.ConnectionParameters(**self._conn_params_dict),
                self.on_connection_open,
                self.on_connection_error_open,
                stop_ioloop_on_close=True,
        ) 
开发者ID:CERT-Polska,项目名称:n6,代码行数:23,代码来源:queue.py

示例3: connect

# 需要导入模块: import pika [as 别名]
# 或者: from pika import SelectConnection [as 别名]
def connect(self):
        """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

        """
        return pika.SelectConnection(
            pika.ConnectionParameters(
                host='localhost',
                virtual_host=self.VIRTUAL_HOST,
                credentials=self.CREDENTIALS
            ),
            self.on_connection_open,
            stop_ioloop_on_close=False
        ) 
开发者ID:alirizakeles,项目名称:ab-2018,代码行数:19,代码来源:rpc_server.py

示例4: initialise_pika_select_connection

# 需要导入模块: import pika [as 别名]
# 或者: from pika import SelectConnection [as 别名]
def initialise_pika_select_connection(
    parameters: "Parameters",
    on_open_callback: Callable[["SelectConnection"], None],
    on_open_error_callback: Callable[["SelectConnection", Text], None],
) -> "SelectConnection":
    """Create a non-blocking Pika `SelectConnection`.

    Args:
        parameters: Parameters which should be used to connect.
        on_open_callback: Callback which is called when the connection was established.
        on_open_error_callback: Callback which is called when connecting to the broker
            failed.

    Returns:
        A callback-based connection to the RabbitMQ event broker.
    """
    import pika

    return pika.SelectConnection(
        parameters,
        on_open_callback=on_open_callback,
        on_open_error_callback=on_open_error_callback,
    ) 
开发者ID:botfront,项目名称:rasa-for-botfront,代码行数:25,代码来源:pika.py

示例5: open_select_connection

# 需要导入模块: import pika [as 别名]
# 或者: from pika import SelectConnection [as 别名]
def open_select_connection(self,
                               on_open_callback              = None,
                               on_open_error_callback        = None,
                               on_close_callback             = None,
                               stop_ioloop_on_close          = True,
                              ):
        tolog("MQ ARGO: create select connection")
        self.create_connection_parameters()
        # open the connection
        if on_open_callback is not None:
            try:
                self.connection = pika.SelectConnection(self.parameters,
                                                        on_open_callback,
                                                        on_open_error_callback,
                                                        on_close_callback,
                                                        stop_ioloop_on_close,
                                                        )
            except:
                tolog('MQ ARGO: Exception received while trying to open select connection to message server: ' + str(sys.exc_info()))
                raise 
开发者ID:PanDAWMS,项目名称:pilot,代码行数:22,代码来源:MessageInterface.py

示例6: connect

# 需要导入模块: import pika [as 别名]
# 或者: from pika import SelectConnection [as 别名]
def connect(self):
        """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

        """
        try:
            log.info('Connecting to %s', self._url)
            return pika.SelectConnection(
                        pika.ConnectionParameters(
                            host=self._host,
                            port=self._port,
                            virtual_host=self._virtual_host,
                            credentials=pika.PlainCredentials(self._username, self._amqp_password),
                            heartbeat_interval=600,
                            blocked_connection_timeout=300),
                        self.on_connection_open,
                        stop_ioloop_on_close=False,
                        )
        except AMQPConnectionError:
            raise ValueError("Error connecting to the AMQP instance, double check credentials and any proxy settings") 
开发者ID:ibmresilient,项目名称:resilient-community-apps,代码行数:25,代码来源:amqp_async_consumer.py

示例7: on_connection_open

# 需要导入模块: import pika [as 别名]
# 或者: from pika import SelectConnection [as 别名]
def on_connection_open(self, unused_connection):
        """This method is called by pika once the connection to RabbitMQ has
        been established. It passes the handle to the connection object in
        case we need it, but in this case, we'll just mark it unused.

        :type unused_connection: pika.SelectConnection

        """
        self.logger.info('Connection opened')
        self.add_on_connection_close_callback()
        self.open_channel() 
开发者ID:openSUSE,项目名称:openSUSE-release-tools,代码行数:13,代码来源:PubSubConsumer.py

示例8: run

# 需要导入模块: import pika [as 别名]
# 或者: from pika import SelectConnection [as 别名]
def run(self, runtime=None):
        """Run the example consumer by connecting to RabbitMQ and then
        starting the IOLoop to block and allow the SelectConnection to operate.

        """
        if runtime:
            self._run_until = time.time() + runtime
        self._connection = self.connect()
        self._connection.ioloop.start() 
开发者ID:openSUSE,项目名称:openSUSE-release-tools,代码行数:11,代码来源:PubSubConsumer.py

示例9: on_connection_open

# 需要导入模块: import pika [as 别名]
# 或者: from pika import SelectConnection [as 别名]
def on_connection_open(self, connection):
        """
        From pika docs:

        This method is called by pika once the connection to RabbitMQ has
        been established. It passes the handle to the connection object.

        Args:
            `connection`: pika.SelectConnection instance
        """
        LOGGER.info('Connection opened')
        self._connection.add_on_close_callback(self.on_connection_closed)
        self.open_channels() 
开发者ID:CERT-Polska,项目名称:n6,代码行数:15,代码来源:queue.py

示例10: connect

# 需要导入模块: import pika [as 别名]
# 或者: from pika import SelectConnection [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

示例11: connect

# 需要导入模块: import pika [as 别名]
# 或者: from pika import SelectConnection [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

示例12: __init__

# 需要导入模块: import pika [as 别名]
# 或者: from pika import SelectConnection [as 别名]
def __init__(self, host: VirtualHost, queue: str, logger: logging.Logger, name: str, durable: bool = True,
                 queue_arguments: dict = None, exchange_arguments: dict = None):
        """
        :param host: the host the queue to consume from is attached to
        :type host: :class:`carrot.objects.VirtualHost`
        :param str queue: the queue to consume from
        :param logger: the logging object
        :param name: the name of the consumer

        """
        super().__init__()

        if queue_arguments is None:
            queue_arguments = {}

        if not exchange_arguments:
            exchange_arguments = {}

        self.failure_callbacks: List[Callable] = []
        self.name = name
        self.logger = logger
        self.queue = queue
        self.exchange = queue

        self.connection: pika.SelectConnection = None
        self.channel: pika.channel = None
        self.shutdown_requested = False
        self._consumer_tag = None
        self._url = str(host)

        self.queue_arguments = queue_arguments
        self.exchange_arguments = exchange_arguments
        self.durable = durable 
开发者ID:chris104957,项目名称:django-carrot,代码行数:35,代码来源:consumer.py

示例13: connect

# 需要导入模块: import pika [as 别名]
# 或者: from pika import SelectConnection [as 别名]
def connect(self) -> pika.SelectConnection:
        """
        Connects to the broker
        """
        self.logger.info('Connecting to %s', self._url)
        return pika.SelectConnection(pika.URLParameters(self._url), self.on_connection_open, stop_ioloop_on_close=False) 
开发者ID:chris104957,项目名称:django-carrot,代码行数:8,代码来源:consumer.py

示例14: on_connection_open

# 需要导入模块: import pika [as 别名]
# 或者: from pika import SelectConnection [as 别名]
def on_connection_open(self, connection: pika.SelectConnection) -> None:
        """
        Callback that gets called when the connection is opened. Adds callback in case of a closed connection, and
        establishes the connection channel

        The `connection` parameter here is not used, as `self.connection` is defined elsewhere, but is included so that
        the signature matches as per Pika's requirements
        """
        self.logger.info('Connection opened')
        self.connection.add_on_close_callback(self.on_connection_closed)
        self.connection.channel(on_open_callback=self.on_channel_open) 
开发者ID:chris104957,项目名称:django-carrot,代码行数:13,代码来源:consumer.py

示例15: connect

# 需要导入模块: import pika [as 别名]
# 或者: from pika import SelectConnection [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


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