當前位置: 首頁>>代碼示例>>Python>>正文


Python pika.PlainCredentials方法代碼示例

本文整理匯總了Python中pika.PlainCredentials方法的典型用法代碼示例。如果您正苦於以下問題:Python pika.PlainCredentials方法的具體用法?Python pika.PlainCredentials怎麽用?Python pika.PlainCredentials使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pika的用法示例。


在下文中一共展示了pika.PlainCredentials方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: connect

# 需要導入模塊: import pika [as 別名]
# 或者: from pika import PlainCredentials [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: keystone_amq

# 需要導入模塊: import pika [as 別名]
# 或者: from pika import PlainCredentials [as 別名]
def keystone_amq(self):
        """
        Method used to listen to keystone events
        """

        connection = pika.BlockingConnection(pika.ConnectionParameters(host=self.rabbit_host,
                                                                       credentials=pika.PlainCredentials(
                                                                           username=self.rabbit_user,
                                                                           password=self.rabbit_pass)))
        channel = connection.channel()
        result = channel.queue_declare(exclusive=True)
        queue_name = result.method.queue
        channel.exchange_declare(exchange='keystone', type='topic')
        channel.queue_bind(exchange='openstack', queue=queue_name, routing_key='notifications.#')
        channel.queue_bind(exchange='keystone', queue=queue_name, routing_key='keystone.#')
        channel.basic_consume(self.keystone_callback, queue=queue_name, no_ack=True)
        channel.start_consuming() 
開發者ID:OneSourceConsult,項目名稱:ZabbixCeilometer-Proxy,代碼行數:19,代碼來源:project_handler.py

示例3: nova_amq

# 需要導入模塊: import pika [as 別名]
# 或者: from pika import PlainCredentials [as 別名]
def nova_amq(self):
        """
        Method used to listen to nova events

        """

        connection = pika.BlockingConnection(pika.ConnectionParameters(host=self.rabbit_host,
                                                                       credentials=pika.PlainCredentials(
                                                                           username=self.rabbit_user,
                                                                           password=self.rabbit_pass)))
        channel = connection.channel()
        result = channel.queue_declare(exclusive=True)
        queue_name = result.method.queue
        channel.exchange_declare(exchange='nova', type='topic')
        channel.queue_bind(exchange='nova', queue=queue_name, routing_key='notifications.#')
        channel.queue_bind(exchange='nova', queue=queue_name, routing_key='compute.#')
        channel.basic_consume(self.nova_callback, queue=queue_name, no_ack=True)
        channel.start_consuming() 
開發者ID:OneSourceConsult,項目名稱:ZabbixCeilometer-Proxy,代碼行數:20,代碼來源:nova_handler.py

示例4: get_connection_amqp

# 需要導入模塊: import pika [as 別名]
# 或者: from pika import PlainCredentials [as 別名]
def get_connection_amqp():
    try:
        port = int(config.get('ckan.harvest.mq.port', PORT))
    except ValueError:
        port = PORT
    userid = config.get('ckan.harvest.mq.user_id', USERID)
    password = config.get('ckan.harvest.mq.password', PASSWORD)
    hostname = config.get('ckan.harvest.mq.hostname', HOSTNAME)
    virtual_host = config.get('ckan.harvest.mq.virtual_host', VIRTUAL_HOST)

    credentials = pika.PlainCredentials(userid, password)
    parameters = pika.ConnectionParameters(host=hostname,
                                           port=port,
                                           virtual_host=virtual_host,
                                           credentials=credentials,
                                           frame_max=10000)
    log.debug("pika connection using %s" % parameters.__dict__)

    return pika.BlockingConnection(parameters) 
開發者ID:italia,項目名稱:daf-recipes,代碼行數:21,代碼來源:queue.py

示例5: _listen_thread

# 需要導入模塊: import pika [as 別名]
# 或者: from pika import PlainCredentials [as 別名]
def _listen_thread(self, thread_idx):
        conn = pika.BlockingConnection(pika.ConnectionParameters(host=self._rmq_server_addr,port=self._port,heartbeat=self.heartbeat,blocked_connection_timeout=None,virtual_host='/',credentials=pika.PlainCredentials(self._username,self._username)))

        channel_request = conn.channel()
        channel_request.queue_declare(queue=self._request_pipe_name)

        channel_response = conn.channel()
        channel_response.queue_declare(queue=self._response_pipe_name)

        def fail(*args,**kwargs):
            print('args:',args)
            print('kwargs:',kwargs)
            raise NotImplementedError

        channel_response.add_on_cancel_callback(fail)

        channel_request.basic_qos(prefetch_count=1) 
        channel_request.basic_consume(partial(self._request_callback, channel_response=channel_response), queue=self._request_pipe_name)

        printgreen(info_prefix(),'Listening ({})'.format(thread_idx))
        print()
        channel_request.start_consuming() 
開發者ID:megvii-model,項目名稱:DetNAS,代碼行數:24,代碼來源:mq_server_base.py

示例6: connect

# 需要導入模塊: import pika [as 別名]
# 或者: from pika import PlainCredentials [as 別名]
def connect(self):
        try:
            self.connected_node = self.broker_manager.get_current_node(self.consumer_id)
            ip = self.broker_manager.get_node_ip(self.connected_node)
            console_out(f"Connecting to {self.connected_node}", self.get_actor())
            credentials = pika.PlainCredentials('jack', 'jack')
            parameters = pika.ConnectionParameters(ip,
                                                self.broker_manager.get_consumer_port(self.connected_node, self.consumer_id),
                                                '/',
                                                credentials)
            self.connection = pika.BlockingConnection(parameters)
            self.channel = self.connection.channel()

            if self.prefetch > 0:
                self.channel.basic_qos(prefetch_count=self.prefetch)

            return True
        except Exception as e:
            console_out_exception("Failed trying to connect.", e, self.get_actor())
            return False 
開發者ID:Vanlightly,項目名稱:ChaosTestingCode,代碼行數:22,代碼來源:MultiTopicConsumer.py

示例7: __init__

# 需要導入模塊: import pika [as 別名]
# 或者: from pika import PlainCredentials [as 別名]
def __init__(self, jobs, responses, host='localhost', port=5672,
                 user='guest', password='guest', rabbit_queue='rpc_queue'):
        # Set connection and channel
        self.credentials = pika.PlainCredentials(user, password)
        self.parameters = pika.ConnectionParameters(host, port, '/', self.credentials)
        self.connection = pika.BlockingConnection(self.parameters)
        self.channel = self.connection.channel()
        # Set queue for jobs and callback queue for responses
        result = self.channel.queue_declare(exclusive=True)
        self.callback_queue = result.method.queue
        self.channel.basic_consume(self.on_response, no_ack=True, queue=self.callback_queue)
        self.rabbit_queue = rabbit_queue
        self.channel.queue_declare(queue=self.rabbit_queue)
        self.response = None
        self.id = None
        # Local queues shared between threads
        self.jobs = jobs
        self.responses = responses
        # Report to the RabbitMQ server
        heartbeat_thread = threading.Thread(target=self.heartbeat)
        heartbeat_thread.daemon = True
        heartbeat_thread.start() 
開發者ID:gmontamat,項目名稱:gentun,代碼行數:24,代碼來源:server.py

示例8: create_connection_parameters

# 需要導入模塊: import pika [as 別名]
# 或者: from pika import PlainCredentials [as 別名]
def create_connection_parameters(self):
        tolog("MQ ARGO: create connection parameters, server = " + self.host + " port = " + str(self.port))
        # need to set credentials to login to the message server
        #self.credentials = pika.PlainCredentials(self.username,self.password)
        self.credentials = pika.credentials.ExternalCredentials()
        ssl_options_dict = {
                            "certfile":  self.ssl_cert,
                            "keyfile":   self.ssl_key,
                            "ca_certs":  self.ssl_ca_certs,
                            "cert_reqs": ssl.CERT_REQUIRED,
                           }
    
                            
        #logger.debug(str(ssl_options_dict))
        # setup our connection parameters
        self.parameters = pika.ConnectionParameters(
                                                    host               = self.host,
                                                    port               = self.port,
                                                    virtual_host       = self.virtual_host,
                                                    credentials        = self.credentials,
                                                    socket_timeout     = self.socket_timeout,
                                                    ssl                = True,
                                                    ssl_options        = ssl_options_dict,
                                                   ) 
開發者ID:PanDAWMS,項目名稱:pilot,代碼行數:26,代碼來源:MessageInterface.py

示例9: __init__

# 需要導入模塊: import pika [as 別名]
# 或者: from pika import PlainCredentials [as 別名]
def __init__(self, host, virtual_host, username, amqp_password, port):
        self.DEFAULT_PORT = 5672

        self.connection = pika.BlockingConnection(
            pika.ConnectionParameters(
                host=host,
                port=int(port) if not isinstance(port, type(None)) else self.DEFAULT_PORT,  # Use provided port no or default if provided port is falsey
                virtual_host=virtual_host,
                credentials=pika.PlainCredentials(username, amqp_password)
            ))

        self.channel = self.connection.channel()

        result = self.channel.queue_declare(exclusive=True)
        self.callback_queue = result.method.queue

        self.channel.basic_consume(self.on_response, no_ack=True,
                                   queue=self.callback_queue) 
開發者ID:ibmresilient,項目名稱:resilient-community-apps,代碼行數:20,代碼來源:amqp_facade.py

示例10: connect

# 需要導入模塊: import pika [as 別名]
# 或者: from pika import PlainCredentials [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

示例11: _setup_mqtt_channel

# 需要導入模塊: import pika [as 別名]
# 或者: from pika import PlainCredentials [as 別名]
def _setup_mqtt_channel(username, password, host, vhost, exchange, routing_key,
                        queue_name):
    credentials = pika.PlainCredentials(username, password)
    connection = pika.BlockingConnection(
        pika.ConnectionParameters(host=host,
                                  credentials=credentials,
                                  virtual_host=vhost))
    channel = connection.channel()

    channel.exchange_declare(exchange=exchange, exchange_type='topic',
                             durable=True)

    result = channel.queue_declare(queue_name, exclusive=True)
    queue_name = result.method.queue

    channel.queue_bind(exchange=exchange,
                       queue=queue_name,
                       routing_key=routing_key)
    return channel 
開發者ID:marionleborgne,項目名稱:cloudbrain,代碼行數:21,代碼來源:mqtt.py

示例12: __init__

# 需要導入模塊: import pika [as 別名]
# 或者: from pika import PlainCredentials [as 別名]
def __init__(self, host, port, username, password, virtual_host, exchange,
                routing_key, durable, exchange_type):

        # create connection parameters
        credentials = pika.PlainCredentials(username, password)
        parameters = pika.ConnectionParameters(host, port, virtual_host,
                                               credentials)

        # create connection & channel
        self.connection = pika.BlockingConnection(parameters)
        self.channel = self.connection.channel()

        # create an exchange, if needed
        self.channel.exchange_declare(exchange=exchange,
                                      exchange_type=exchange_type,
                                      durable=durable)

        # needed when publishing
        self.spec = pika.spec.BasicProperties(delivery_mode=2)
        self.routing_key = routing_key
        self.exchange = exchange 
開發者ID:israel-fl,項目名稱:python3-logstash,代碼行數:23,代碼來源:handler_amqp.py

示例13: connect

# 需要導入模塊: import pika [as 別名]
# 或者: from pika import PlainCredentials [as 別名]
def connect(self, num_tries=3):
		credentials = pika.PlainCredentials(config.get('rabbitmq')['user'], config.get('rabbitmq')['password'])
		parameters = pika.ConnectionParameters(credentials=credentials,
			host=config.get('rabbitmq')['master_ip'],
			port=5671,
			ssl=True,
			socket_timeout=10,
			ssl_options = {
				"ca_certs":PROJECT_PATH+"/certs/"+config.get('rabbitmq')['cacert'],
				"certfile":PROJECT_PATH+"/certs/"+config.get('rabbitmq')['certfile'],
				"keyfile":PROJECT_PATH+"/certs/"+config.get('rabbitmq')['keyfile']
			}
		)

		connected = False
		while not connected and num_tries > 0:
			try:
				cherrypy.log("Trying to connect to rabbitmq service...")
				self.connection = pika.BlockingConnection(parameters=parameters)
				self.channel = self.connection.channel()
				connected = True
				cherrypy.log("Connection to rabbitmq service established")
			#except pika.exceptions.AMQPConnectionError as pe:
			except Exception as e:
				cherrypy.log("Error connecting to Queue! %s" % e, traceback=True)
				num_tries-=1
				time.sleep(30)

		if not connected:
			return False
		# define exchange
		self.channel.exchange_declare(exchange=utils.EXCHANGE, exchange_type='direct')

		# define queues
		self.channel.queue_declare(queue=utils.QUEUE_ON_OFF)
		self.channel.queue_bind(exchange=utils.EXCHANGE, queue=utils.QUEUE_ON_OFF)
		return True 
開發者ID:SecPi,項目名稱:SecPi,代碼行數:39,代碼來源:main.py

示例14: index_mq_aucr_task

# 需要導入模塊: import pika [as 別名]
# 或者: from pika import PlainCredentials [as 別名]
def index_mq_aucr_task(rabbit_mq_server, task_name, routing_key):
    """Create MQ aucr task."""
    rabbitmq_username = os.environ.get('RABBITMQ_USERNAME') or 'guest'
    rabbitmq_password = os.environ.get('RABBITMQ_PASSWORD') or 'guest'
    credentials = pika.PlainCredentials(rabbitmq_username, rabbitmq_password)
    connection = pika.BlockingConnection(pika.ConnectionParameters(credentials=credentials, host=rabbit_mq_server))
    channel = connection.channel()
    channel.basic_publish(exchange='',  routing_key=routing_key,  body=task_name)
    connection.close() 
開發者ID:AUCR,項目名稱:AUCR,代碼行數:11,代碼來源:mq.py

示例15: get_mq_aucr_tasks

# 需要導入模塊: import pika [as 別名]
# 或者: from pika import PlainCredentials [as 別名]
def get_mq_aucr_tasks(call_back, rabbit_mq_server, rabbit_mq_que, rabbitmq_username, rabbitmq_password):
    """Start MQ message consumer."""
    credentials = pika.PlainCredentials(rabbitmq_username, rabbitmq_password)
    connection = pika.BlockingConnection(pika.ConnectionParameters(credentials=credentials, host=rabbit_mq_server))
    channel = connection.channel()
    channel.queue_declare(queue=rabbit_mq_que)
    channel.basic_consume(on_message_callback=call_back, queue=rabbit_mq_que)
    channel.start_consuming()
    connection.close() 
開發者ID:AUCR,項目名稱:AUCR,代碼行數:11,代碼來源:mq.py


注:本文中的pika.PlainCredentials方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。