Example #1
0
 def __init__(self, connection=None, bind_queue=True):
     from amqp import get_connection
     if not connection:
         connection = get_connection()
         # hold on to this connection since it was created here
         self.connection = connection
     else:
         self.connection = None
     channel = connection.channel()
     channel.access_request('/data', active=True, read=True, write=True)
     self.channel = channel
     if bind_queue:
         channel.exchange_declare(self.exchange_name, self.exchange_type, auto_delete=self.auto_delete, durable=self.durable)
         self.qname, _, _ = channel.queue_declare(queue=self.queue_name, exclusive=self.exclusive, durable=self.durable, auto_delete=self.auto_delete)
         channel.queue_bind(self.qname, self.exchange_name, routing_key=self.routing_key)
         if self.blocking:
             channel.basic_consume(self.qname, callback=self.callback, no_ack=self.no_ack)
         _x().debug("Bound to Q %s at %s/%s", self.qname, self.exchange_name, self.routing_key)
Example #2
0
from wsgiref.simple_server import WSGIServer, WSGIRequestHandler
import multiprocessing.pool
import json
import traceback
import shutil
import os
import amqp
import time
from app import app
import db

import urlparse

amqp.get_amqplib_connection()
amqp.get_connection()
db.get_connections()

def application(environ, start_response):

    start_time = time.time()
    output = {}

    try:
        output = app(
            command_name=environ['PATH_INFO'].strip('/'),
            data=urlparse.parse_qs(environ['QUERY_STRING'])
        )
    except Exception as e:
        output['error'] = str(e)
        traceback.print_exc()