How to use the pika.PlainCredentials function in pika

To help you get started, we’ve selected a few pika examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github alirizakeles / ab-2018 / src / github_worker / github_worker.py View on Github external
break

        for repo in response:
            if is_exists_in_db(github_sub, repo):
                break
            else:
                add_into_db(github_sub, repo)

            github_params["page"] += 1


connection = pika.BlockingConnection(
    pika.ConnectionParameters(
        host=RABBIT_HOST,
        virtual_host=VIRTUAL_HOST,
        credentials=pika.PlainCredentials(RABBIT_USER, RABBIT_PASSWORD)
    )
)

channel = connection.channel()

channel.exchange_declare(exchange='work',
                         exchange_type='direct')

channel.queue_bind(exchange='work',
                   queue='github_queue',
                   routing_key='github')

channel.basic_consume(on_request, queue=GITHUB_WORKER_QUEUE, no_ack=True)

channel.start_consuming()
github dfoderick / fullcycle / fullcyclepy / backend / fcmbus.py View on Github external
def connection(self):
        if not self._connection:
            credentials = pika.PlainCredentials(self._userlogin, self._servicelogin.password)
            parameters = pika.ConnectionParameters(self._servicelogin.host, self._servicelogin.port, '/', credentials)
            self._connection = pika.BlockingConnection(parameters)
        return self._connection
github AUCR / AUCR / aucr_app / plugins / tasks / mq.py View on Github external
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()
github waggle-sensor / waggle / other / version0.2_stable / core / frameworks / common / waggle / device / node_controller / data_client.py View on Github external
def __init__(self, RMQ_ip, port, user, passwd, exch, rout_key):
        """ Initializer of data client, all parameters needed to be filled so
            to access the remote server. Please see example at the bottom for
            use.
        """
        self.RMQHost = RMQ_ip
        self.RMQPort = int(port)
        self.RMQUser = user
        self.RMQPassWd = passwd
        self.RMQExchange = exch
        self.RMQRoutingKey = rout_key

        credentials = pika.PlainCredentials(self.RMQUser, self.RMQPassWd)

        self.connection = pika.BlockingConnection(pika.ConnectionParameters(
                                host = self.RMQHost, port = self.RMQPort, 
                                credentials= credentials))

        self.channel = self.connection.channel()
        self.delimiter0 = DELIMITERS[0]
github waggle-sensor / beehive-server / beehive-loader-raw / loader.py View on Github external
print("RABBITMQ_HOST: {}".format(RABBITMQ_HOST))
print("RABBITMQ_PORT: {}".format(RABBITMQ_PORT))

print("CASSANDRA_HOSTS: {}".format(CASSANDRA_HOSTS))




connection = pika.BlockingConnection(pika.ConnectionParameters(
    host=RABBITMQ_HOST,
    port=RABBITMQ_PORT,
    virtual_host=BEEHIVE_DEPLOYMENT,
    credentials=pika.PlainCredentials(
        username=RABBITMQ_USERNAME,
        password=RABBITMQ_PASSWORD,
    ),
    connection_attempts=10,
    retry_delay=3.0))

channel = connection.channel()
# channel.basic_qos(prefetch_count=1)
queue = 'db-raw'
channel.basic_consume(queue, process_message)
channel.start_consuming()
github klee / klee-web / python / worker / rpc_client.py View on Github external
#!/usr/bin/env python
import pika
import uuid
import os

RABBITMQ_HOST = os.environ['RABBITMQ_HOST']
RABBITMQ_USERNAME = os.environ['RABBITMQ_USERNAME']
RABBITMQ_PASSWORD = os.environ['RABBITMQ_PASSWORD']
RABBITMQ_VHOST = os.environ['RABBITMQ_VHOST']

credentials = pika.PlainCredentials(username=RABBITMQ_USERNAME, password=RABBITMQ_PASSWORD)


class FibonacciRpcClient(object):
    def __init__(self):
        self.connection = pika.BlockingConnection(pika.ConnectionParameters(
            host=RABBITMQ_HOST, credentials=credentials, virtual_host=RABBITMQ_VHOST))

        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)

    def on_response(self, ch, method, props, body):
github vmware / container-service-extension / container_service_extension / configure_cse.py View on Github external
:param str exchange_name: The AMQP exchange name to check for or create.
    :param str host: AMQP host name.
    :param str password: AMQP password.
    :param int port: AMQP port number.
    :param bool use_ssl: Enable ssl.
    :param str username: AMQP username.
    :param str vhost: AMQP vhost.
    :param utils.ConsoleMessagePrinter msg_update_callback: Callback object.

    :raises cse_exception.AmqpError: if AMQP exchange could not be created.
    """
    msg = f"Checking for AMQP exchange '{exchange_name}'"
    msg_update_callback.info(msg)
    INSTALL_LOGGER.info(msg)
    credentials = pika.PlainCredentials(username, password)
    parameters = pika.ConnectionParameters(host, port, vhost, credentials,
                                           ssl=use_ssl, connection_attempts=3,
                                           retry_delay=2, socket_timeout=5)
    connection = None
    try:
        connection = pika.BlockingConnection(parameters)
        channel = connection.channel()
        channel.exchange_declare(exchange=exchange_name,
                                 exchange_type=server_constants.EXCHANGE_TYPE,
                                 durable=True, auto_delete=False)
    except Exception as err:
        msg = f"Cannot create AMQP exchange '{exchange_name}'"
        msg_update_callback.error(msg)
        INSTALL_LOGGER.error(msg, exc_info=True)
        raise cse_exception.AmqpError(msg, str(err))
    finally:
github waggle-sensor / beehive-server / data-pipeline / QueueToDb.py View on Github external
self.queue = 'db-raw'
            self.statement = "INSERT INTO sensor_data_raw (node_id, date, plugin_name, plugin_version, plugin_instance, timestamp, parameter, data) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"
            self.function_ExtractValuesFromMessage = self.ExtractValuesFromMessage_raw
        else:
            self.input_exchange = 'plugins-out'
            self.queue = 'db-decoded'
            self.statement = "INSERT INTO sensor_data_decoded (node_id, date, ingest_id, meta_id, timestamp, data_set, sensor, parameter, data, unit) VALUES (?, ?, ?, ?, ?,   ?, ?, ?, ?, ?)"
            self.function_ExtractValuesFromMessage = self.ExtractValuesFromMessage_decoded

        logger.info("Initializing DataProcess")

        self.connection = pika.BlockingConnection(pika.ConnectionParameters(
            host='beehive-rabbitmq',
            port=5672,
            virtual_host=BEEHIVE_DEPLOYMENT,
            credentials=pika.PlainCredentials(
                username='loader_raw',
                password='waggle',
            ),
            connection_attempts=10,
            retry_delay=3.0))

        self.verbosity = verbosity
        self.numInserted = 0
        self.numFailed = 0
        self.session = None
        self.cluster = None
        self.prepared_statement = None

        self.cassandra_connect()

        self.channel = self.connection.channel()
github cenkalti / kuyruk / kuyruk / connection.py View on Github external
def open(self):
        super(LazyConnection, self).open()
        credentials = pika.PlainCredentials(self.user, self.password)
        parameters = pika.ConnectionParameters(
            host=self.host, port=self.port, credentials=credentials)
        self.real = pika.BlockingConnection(parameters)
        logger.info('Connected to RabbitMQ')
github robomq / robomq.io / sdk / AMQP / python / routing-key / producer.py View on Github external
# Author: Stanley
# robomq.io (http://www.robomq.io)

import pika

server = "hostname"
port = 5672
vhost = "yourvhost"
username = "username"
password = "password"
exchangeName = "testEx"
routingKey = "test"

try:
	#connect
	credentials = pika.PlainCredentials(username, password)
	connection = pika.BlockingConnection(pika.ConnectionParameters(host = server, port = port, virtual_host = vhost, credentials = credentials))
	channel = connection.channel()

	#send message
	properties = pika.spec.BasicProperties(content_type = "text/plain", delivery_mode = 1)
	channel.basic_publish(exchange = exchangeName, routing_key = routingKey, body = "Hello World!", properties = properties)

	#disconnect
	connection.close()
except Exception, e:
	print e