Python pika.PlainCredentials() Examples
The following are 30
code examples of pika.PlainCredentials().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pika
, or try the search function
.
Example #1
Source File: amqp_async_consumer.py From resilient-community-apps with MIT License | 8 votes |
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")
Example #2
Source File: nova_handler.py From ZabbixCeilometer-Proxy with Apache License 2.0 | 6 votes |
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()
Example #3
Source File: MessageInterface.py From pilot with Apache License 2.0 | 6 votes |
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, )
Example #4
Source File: MultiTopicConsumer.py From ChaosTestingCode with MIT License | 6 votes |
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
Example #5
Source File: server.py From gentun with Apache License 2.0 | 6 votes |
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()
Example #6
Source File: amqp_facade.py From resilient-community-apps with MIT License | 6 votes |
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)
Example #7
Source File: mq_server_base.py From DetNAS with MIT License | 6 votes |
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()
Example #8
Source File: queue.py From daf-recipes with GNU General Public License v3.0 | 6 votes |
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)
Example #9
Source File: project_handler.py From ZabbixCeilometer-Proxy with Apache License 2.0 | 6 votes |
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()
Example #10
Source File: mqtt.py From cloudbrain with GNU Affero General Public License v3.0 | 6 votes |
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
Example #11
Source File: PubSubConsumer.py From openSUSE-release-tools with GNU General Public License v2.0 | 6 votes |
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)
Example #12
Source File: PubSubConsumer.py From openSUSE-release-tools with GNU General Public License v2.0 | 6 votes |
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)
Example #13
Source File: handler_amqp.py From python3-logstash with MIT License | 6 votes |
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
Example #14
Source File: consumers.py From FFXIVBOT with GNU General Public License v3.0 | 5 votes |
def __init__(self, username="guest", password="guest", queue="ffxivbot"): # print("initializing pika publisher") self.credentials = pika.PlainCredentials(username, password) self.queue = queue self.parameters = pika.ConnectionParameters( "127.0.0.1", 5672, "/", self.credentials, heartbeat=0 ) self.connection = pika.BlockingConnection(self.parameters) self.channel = self.connection.channel() self.priority_queue = {"x-max-priority": 20, "x-message-ttl": 60000} self.channel.queue_declare(queue=self.queue, arguments=self.priority_queue)
Example #15
Source File: server.py From ab-2018 with GNU General Public License v3.0 | 5 votes |
def __init__(self): super(SubscriptionList, self).__init__() self.redis_client = redis.Redis(host=REDIS_HOST, port=REDIS_PORT) connection = pika.BlockingConnection( pika.ConnectionParameters( host=RABBIT_HOST, virtual_host=VIRTUAL_HOST, credentials=pika.PlainCredentials(RABBIT_USER, RABBIT_PASSWORD) ) ) self.channel = connection.channel() self.channel.queue_declare(queue=QUEUE_NAME, durable=True)
Example #16
Source File: scheduler.py From ab-2018 with GNU General Public License v3.0 | 5 votes |
def __init__(self): self.QUEUE = 'ab18-.rpc_queue' self.EXCHANGE = 'ab18-.exchange' self.VIRTUAL_HOST = 'ab18' self.CREDENTIALS = pika.PlainCredentials('ab18', '1') self._closing = False super(RpcServer, self).__init__()
Example #17
Source File: utils.py From listenbrainz-server with GNU General Public License v2.0 | 5 votes |
def connect_to_rabbitmq(username, password, host, port, virtual_host, connection_type=pika.BlockingConnection, credentials_type=pika.PlainCredentials, error_logger=print, error_retry_delay=3, heartbeat=None): """Connects to RabbitMQ Args: username, password, host, port, virtual_host error_logger: A function used to log failed connections. connection_type: A pika Connection class to instantiate. credentials_type: A pika Credentials class to use. error_retry_delay: How long to wait in seconds before retrying a connection. Returns: A connection, with type of connection_type. """ while True: try: credentials = credentials_type(username, password) connection_parameters = pika.ConnectionParameters( host=host, port=port, virtual_host=virtual_host, credentials=credentials, heartbeat=heartbeat, ) return connection_type(connection_parameters) except Exception as err: error_message = "Cannot connect to RabbitMQ: {error}, retrying in {delay} seconds." error_logger(error_message.format(error=str(err), delay=error_retry_delay)) time.sleep(error_retry_delay)
Example #18
Source File: rabbitmq_reader.py From cito_engine with Apache License 2.0 | 5 votes |
def __init__(self): self.credentials = pika.PlainCredentials(settings.RABBITMQ_CONF['username'], settings.RABBITMQ_CONF['password']) self.channel = None self.connection = None
Example #19
Source File: RabbitMq.py From sgx-kms with Apache License 2.0 | 5 votes |
def __init__(self): credentials = self.init_env_variables() self.credentials = pika.PlainCredentials(credentials['username'], credentials['password']) self.params = pika.ConnectionParameters(credentials['host'], int(credentials['port']), credentials['virtual_host'], self.credentials) self.connection = pika.BlockingConnection(self.params) self.channel = self.connection.channel() #Function to publish message using RabbitMq
Example #20
Source File: dispatcher.py From listenbrainz-server with GNU General Public License v2.0 | 5 votes |
def init_rabbitmq_connection(self): while True: try: credentials = pika.PlainCredentials(current_app.config['RABBITMQ_USERNAME'], current_app.config['RABBITMQ_PASSWORD']) connection_parameters = pika.ConnectionParameters( host=current_app.config['RABBITMQ_HOST'], port=current_app.config['RABBITMQ_PORT'], virtual_host=current_app.config['RABBITMQ_VHOST'], credentials=credentials, ) self.connection = pika.SelectConnection(parameters=connection_parameters, on_open_callback=self.on_open) break except Exception as e: current_app.logger.error("Error while connecting to RabbitMQ: %s", str(e), exc_info=True) time.sleep(3)
Example #21
Source File: client.py From gentun with Apache License 2.0 | 5 votes |
def __init__(self, individual, x_train, y_train, host='localhost', port=5672, user='guest', password='guest', rabbit_queue='rpc_queue'): self.individual = individual self.x_train = x_train self.y_train = y_train 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() self.rabbit_queue = rabbit_queue self.channel.queue_declare(queue=self.rabbit_queue) # Report to the RabbitMQ server heartbeat_thread = threading.Thread(target=self.heartbeat) heartbeat_thread.daemon = True heartbeat_thread.start()
Example #22
Source File: broadcast_message_producer.py From whatsapp_automation with GNU General Public License v3.0 | 5 votes |
def __init__(self): rhost = configp.get('rabbitmq', 'ip') username = configp.get('rabbitmq', 'username') password = configp.get('rabbitmq', 'password') credentials = pika.PlainCredentials(username, password) parameters = pika.ConnectionParameters(rhost,5672,'/',credentials) self.connection = pika.BlockingConnection(parameters) self.channel = self.connection.channel() result = self.channel.queue_declare(exclusive=True) self.callback_queue = result.method.queue
Example #23
Source File: single_message_producer.py From whatsapp_automation with GNU General Public License v3.0 | 5 votes |
def __init__(self): rhost = configp.get('rabbitmq', 'ip') username = configp.get('rabbitmq', 'username') password = configp.get('rabbitmq', 'password') credentials = pika.PlainCredentials(username, password) parameters = pika.ConnectionParameters(rhost,5672,'/',credentials) self.connection = pika.BlockingConnection(parameters) self.channel = self.connection.channel() result = self.channel.queue_declare(exclusive=True) self.callback_queue = result.method.queue
Example #24
Source File: add_new_contact_producer.py From whatsapp_automation with GNU General Public License v3.0 | 5 votes |
def __init__(self): rhost = configp.get('rabbitmq', 'ip') username = configp.get('rabbitmq', 'username') password = configp.get('rabbitmq', 'password') credentials = pika.PlainCredentials(username, password) parameters = pika.ConnectionParameters(rhost,5672,'/',credentials) self.connection = pika.BlockingConnection(parameters) self.channel = self.connection.channel() result = self.channel.queue_declare(exclusive=True) self.callback_queue = result.method.queue
Example #25
Source File: new_message_listener_producer.py From whatsapp_automation with GNU General Public License v3.0 | 5 votes |
def __init__(self): rhost = configp.get('rabbitmq', 'ip') username = configp.get('rabbitmq', 'username') password = configp.get('rabbitmq', 'password') credentials = pika.PlainCredentials(username, password) parameters = pika.ConnectionParameters(rhost,5672,'/',credentials) self.connection = pika.BlockingConnection(parameters) self.channel = self.connection.channel() result = self.channel.queue_declare(exclusive=True) self.callback_queue = result.method.queue
Example #26
Source File: mqhelper.py From k8sMG with GNU General Public License v3.0 | 5 votes |
def create_channel(self): credentials = pika.PlainCredentials(self.user, self.pwd) self.__connection = pika.BlockingConnection( pika.ConnectionParameters(self.addr, self.port, self.vhost, credentials=credentials)) channel = self.__connection.channel() return channel
Example #27
Source File: rabbitmq.py From cloudbrain with GNU Affero General Public License v3.0 | 5 votes |
def connect(self): credentials = pika.PlainCredentials(self.rabbitmq_user, self.rabbitmq_pwd) self.connection = pika.BlockingConnection(pika.ConnectionParameters( host=self.rabbitmq_address, virtual_host=self.rabbitmq_vhost, credentials=credentials))
Example #28
Source File: mqtt.py From cloudbrain with GNU Affero General Public License v3.0 | 5 votes |
def _setup_mqtt_channel(username, password, host, vhost, exchange): credentials = pika.PlainCredentials(username, password) params = pika.ConnectionParameters(host=host, credentials=credentials, virtual_host=vhost) connection = pika.BlockingConnection(parameters=params) channel = connection.channel() channel.exchange_declare(exchange=exchange, exchange_type='topic', durable=True) return channel
Example #29
Source File: rabbitmq.py From cloudbrain with GNU Affero General Public License v3.0 | 5 votes |
def connect(self): credentials = pika.PlainCredentials(self.rabbitmq_user, self.rabbitmq_pwd) self.connection = pika.BlockingConnection(pika.ConnectionParameters( host=self.rabbitmq_address, virtual_host=self.rabbitmq_vhost, credentials=credentials))
Example #30
Source File: shareAggr.py From grin-pool with Apache License 2.0 | 5 votes |
def RmqConsumer(host): global LOGGER global RABBITMQ_USER global RABBITMQ_PASSWORD while True: try: credentials = pika.PlainCredentials(RABBITMQ_USER, RABBITMQ_PASSWORD) connection = pika.BlockingConnection( pika.ConnectionParameters( host=host, credentials=credentials ) ) channel = connection.channel() channel.basic_qos( prefetch_size=0, prefetch_count=0, global_qos=True ) # Consume pool block records channel.basic_consume( queue='poolblocks', on_message_callback=poolblock_handler, auto_ack=False ) # Consume worker shares records channel.basic_consume( queue='shares', on_message_callback=share_handler, auto_ack=False ) channel.start_consuming() except Exception as e: LOGGER.exception("Something went wrong: {}".format(traceback.format_exc())) sys.stdout.flush() time.sleep(10)