예제 #1
0
def serve():
    connection = pika.BlockingConnection(pika.URLParameters(get_rabbit_connection_string()))
    channel = connection.channel()

    channel.queue_declare(queue="network")

    print " [*] Waiting for messages. To exit press CTRL+C"

    def callback(ch, method, properties, body):
        method, args, kwargs = json.loads(body)
        getattr(_MODULE, method)(*args, **kwargs)

    channel.basic_consume(callback, queue="network", no_ack=True)

    channel.start_consuming()
예제 #2
0
def serve():
    connection = pika.BlockingConnection(pika.URLParameters(get_rabbit_connection_string()))
    channel = connection.channel()

    channel.queue_declare(queue='vm')

    print ' [*] Waiting for messages. To exit press CTRL+C'

    def callback(ch, method, properties, body):
        method, args, kwargs = json.loads(body)
        try:
            getattr(_MODULE, method)(*args, **kwargs)
        except libvirt.libvirtError as ex:
            print '[ERROR](libvirtError) {}'.format(ex)

    channel.basic_consume(callback, queue='vm', no_ack=True)

    channel.start_consuming()
예제 #3
0
def _send(data):
    connection = pika.BlockingConnection(pika.URLParameters(get_rabbit_connection_string()))
    channel = connection.channel()
    channel.queue_declare(queue='network')
    channel.basic_publish(exchange='', routing_key='network', body=json.dumps(data))
    connection.close()