本文整理汇总了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)
示例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()
示例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()
示例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)
示例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()
示例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
示例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()
示例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,
)
示例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)
示例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")
示例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
示例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
示例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
示例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()
示例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()