How to use the pika.BlockingConnection 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 waggle-sensor / waggle / other / version0.2_stable / core / frameworks / cloud / codes / cloud_pika_connections.py View on Github external
def Consume(callback, routing_key, ip = BEEHIVE_IP, port = BEEHIVE_PORT, username = BEEHIVE_UNAME, password = BEEHIVE_PWD):
    credentials = pika.PlainCredentials(username, password)
    parameters = pika.ConnectionParameters(ip, port, credentials = credentials)
    connection = pika.BlockingConnection(parameters)
    channel = connection.channel()

    channel.queue_declare(queue=routing_key) #auto_delete = true?
    channel.basic_consume(callback, queue=routing_key, no_ack = False) #no_ack?
    channel.start_consuming()
    connection.close()
github waggle-sensor / beehive-server / beehive-queue-to-mysql / QueueToMysql.py View on Github external
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-mysql'
            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")

        # Set up the Rabbit connection
        #self.connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
        #Connect to rabbitMQ
        while True:
            try:
                self.connection = pika.BlockingConnection(pika_params)
            except Exception as e:
                logger.error("QueueToMysql: Could not connect to RabbitMQ server \"%s\": %s" % (pika_params.host, e))
                time.sleep(1)
                continue
            break


        logger.info("Connected to RabbitMQ server \"%s\"" % (pika_params.host))
        self.verbosity = verbosity
        self.numInserted = 0

        self.db_connect()

        self.channel = self.connection.channel()
        self.channel.basic_qos(prefetch_count=1)
        # Declare this process's queue
github pywren / pywren-ibm-cloud / pywren_ibm_cloud / function / jobrunner.py View on Github external
if self.internal_storage.backend == 'ibm_cos':
                    ibm_boto3_client = self.internal_storage.get_client()
                else:
                    ibm_boto3_client = Storage(pywren_config=self.pywren_config, storage_backend='ibm_cos').get_client()
                data['ibm_cos'] = ibm_boto3_client
            else:
                raise Exception('Cannot create the ibm_cos client: missing configuration')

        if 'storage' in func_sig.parameters:
            data['storage'] = self.internal_storage.storage

        if 'rabbitmq' in func_sig.parameters:
            if 'rabbitmq' in self.pywren_config:
                rabbit_amqp_url = self.pywren_config['rabbitmq'].get('amqp_url')
                params = pika.URLParameters(rabbit_amqp_url)
                connection = pika.BlockingConnection(params)
                data['rabbitmq'] = connection
            else:
                raise Exception('Cannot create the rabbitmq client: missing configuration')

        if 'id' in func_sig.parameters:
            data['id'] = int(self.call_id)
github waggle-sensor / beehive-server / data-pipeline / LastUpdate2.py View on Github external
self.input_exchange = 'logs'
            self.queue          = 'last-log'
            self.statement = "INSERT INTO nodes_last_log  (node_id, last_update) VALUES (?, ?)"
        else:
            self.input_exchange = 'data-pipeline-in'
            self.queue          = 'last-data'
            self.statement = "INSERT INTO nodes_last_data (node_id, last_update) VALUES (?, ?)"
        
        logger.info("Initializing LastUpdateProcess")
        
        # Set up the Rabbit connection
        #self.connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
        #Connect to rabbitMQ
        while True:
            try:
                self.connection = pika.BlockingConnection(pika_params)
            except Exception as e:
                logger.error("QueueToDb: Could not connect to RabbitMQ server \"%s\": %s" % (pika_params.host, e))
                time.sleep(1)
                continue
            break
            
        logger.info("Connected to RabbitMQ server \"%s\"" % (pika_params.host))
        self.verbosity = verbosity
        self.numInserted = 0
        self.session = None
        self.cluster = None
        self.prepared_statement = None
        
        self.cassandra_connect()
github uclouvain / osis-portal / exam_enrollment / views / exam_enrollment.py View on Github external
def ask_queue_for_exam_enrollment_form(stud, offer_yr):
    connect = pika.BlockingConnection(_get_rabbit_settings())
    queue_name = settings.QUEUES.get('QUEUES_NAME').get('EXAM_ENROLLMENT_FORM_REQUEST')
    channel = _create_channel(connect, queue_name)
    message = _exam_enrollment_form_message(stud.registration_id, offer_yr.acronym, offer_yr.academic_year.year)
    message_published = channel.basic_publish(exchange='',
                                              routing_key=queue_name,
                                              body=json.dumps(message))
    connect.close()
    return message_published
github mozilla / captain / captain / projects / shove.py View on Github external
def create_connection():
    """Setup a connection to RabbitMQ."""
    parameters = pika.ConnectionParameters(
        host=settings.RABBITMQ_HOST,
        port=settings.RABBITMQ_PORT,
        virtual_host=settings.RABBITMQ_VHOST,
        credentials=pika.credentials.PlainCredentials(
            settings.RABBITMQ_USER,
            settings.RABBITMQ_PASS
        ),
        heartbeat_interval=600,
    )
    return pika.BlockingConnection(parameters)
github allenling / magne / magne / process_worker / bench.py View on Github external
def en_queue(n):
    print('starting en_queue...')
    parameters = pika.URLParameters('amqp://guest:guest@localhost:5672/%2F')

    connection = pika.BlockingConnection(parameters)

    channel = connection.channel()
    print('decalaring exchange and queue')
    try:
        channel.exchange_declare(exchange_name)
        channel.queue_declare(queue_name)
        print('bind')
        channel.queue_bind(queue_name, exchange_name, routing_key)
    except Exception as e:
        print('decalare exchange and queue error: %s' % e)
        raise e
    print('config exchange and queue done')
    print('staring send tasks into rabbitmq')
    for _ in range(n):
        channel.basic_publish('MAGNE_LATENCY_BENCH',
                              'MAGNE_LATENCY_BENCH',