當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。