Example #1
0
def initializeMessageQueue(rabbit_url):

    # this assumes a real external rabbit queue. TODO: create an internal version.

    #rdb = redis.Redis(host=url.hostname, port=url.port, password=url.password)

    messageQ = MessageQueue(rabbit_url)

    return messageQ
Example #2
0
rabbit_url = os.environ['RABBITMQ_URL']
queue_name = os.environ['QUEUE_NAME']

print os.environ['MYSQL_URL']
print os.environ['RABBITMQ_URL']

#rdb = redis.Redis(host=url.hostname, port=url.port, password=url.password)

url = mysql_url.hostname
password = mysql_url.password
user = mysql_url.username
dbname = mysql_url.path[1:] 


messageDB = MessageDB(url,dbname,user,password)
messageQueue = MessageQueue(rabbit_url)
messageQueue.getMessagesAsync(queue_name)
    
@get('/received') 
def getReceived():
    
    log.debug("handling /received path")

    #Gets messages, if method_frame decodes and adds to db
    #messageQueue.getMessages(queue_name,100)
    
    all_messages = messageDB.getMessages()
    
    return json.dumps(all_messages,cls=MessageEncoder)

'''
Example #3
0
mysql_url = urlparse.urlparse(os.environ['MYSQL_URL'])
rabbit_url = os.environ['RABBITMQ_URL']
queue_name = os.environ['QUEUE_NAME']

print os.environ['MYSQL_URL']
print os.environ['RABBITMQ_URL']

#rdb = redis.Redis(host=url.hostname, port=url.port, password=url.password)

url = mysql_url.hostname
password = mysql_url.password
user = mysql_url.username
dbname = mysql_url.path[1:]

messageDB = MessageDB(url, dbname, user, password)
messageQueue = MessageQueue(rabbit_url)
messageQueue.getMessagesAsync(queue_name)


@get('/received')
def getReceived():

    log.debug("handling /received path")

    #Gets messages, if method_frame decodes and adds to db
    #messageQueue.getMessages(queue_name,100)

    all_messages = messageDB.getMessages()

    return json.dumps(all_messages, cls=MessageEncoder)
Example #4
0
try:
    mysql_url = urlparse.urlparse(os.environ['MYSQL_URL'])
except KeyError:
    log.warn("env variable MYSQL_URL not found, reverting to DATABASE_URL")
    mysql_url = urlparse.urlparse(os.environ['DATABASE_URL'])

fibDataDB = initializeDB(mysql_url)

log.debug("setting up message queue")
rabbitUrl = os.environ['RABBITMQ_URL']
jobsQueueName = os.environ['JOBS_QUEUE_NAME']
resultsQueueName = os.environ['RESULTS_QUEUE_NAME']
log.debug("rabbit mq url:%s" % os.environ['RABBITMQ_URL'])

# jobsMessageQueue is what web layer sends work requests to
jobMessageQueue = MessageQueue(rabbitUrl)
jobMessageQueue.createQueue(jobsQueueName)

# resultsMessageQueue is what worker layer sends results back to
resultsMessageQueue = MessageQueue(rabbitUrl)
resultsMessageQueue.createQueue(resultsQueueName)

# need to receive work result requests async in order to also handle web requests

workerT = Thread(name='daemon',
                 target=doWork,
                 args=(resultsMessageQueue, fibDataDB))
workerT.setDaemon(True)
workerT.start()
'''
service runner code
except KeyError:
    log.warn("env variable MYSQL_URL not found, reverting to DATABASE_URL")
    mysql_url = urlparse.urlparse(os.environ['DATABASE_URL'])


workerDataDB = initializeDB(mysql_url)

log.debug("setting up message queue")

rabbitUrl = os.environ['RABBITMQ_URL']
jobQueueName = os.environ['JOBS_QUEUE_NAME']
resultsQueueName = os.environ['RESULTS_QUEUE_NAME']
restInterval  = int(os.getenv('REST_INTERVAL',5))
log.debug("rabbit mq url:%s"%os.environ['RABBITMQ_URL'])

jobMessageQueue = MessageQueue(rabbitUrl)
jobMessageQueue.createQueue(jobQueueName)

resultsMessageQueue = MessageQueue(rabbitUrl)
resultsMessageQueue.createQueue(resultsQueueName)

# worker ID is unique to this instance of worker
log.debug("generating worker ID")
workerId = uuid.uuid1()

# need to receive work requests async in order to also handle web requests

workerT = Thread(name='daemon', target=doWork, args = (jobMessageQueue,resultsMessageQueue,workerDataDB,workerId))
workerT.setDaemon(True)
workerT.start()
Example #6
0
from threading import Thread
import json

with open("config.json") as cfg:
    config = json.load(cfg)
    addr = config["server"]["addr"]
    port = config["server"]["port"]

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((addr, port))

addresses = {}
logins = {}
userSt = UserStore()
aliasSt = aliasStore()
MQ = MessageQueue()


def parse_rec(inp, cli):
    cmd_lst = inp.split(" ")
    cmd_type, cmd_args = cmd_lst[0], cmd_lst[1:]
    if cmd_type == "reg":
        rsd = userSt.register(*cmd_args[:2], " ".join(cmd_args[2:]))
        if rsd:
            return "registered!"
        else:
            return "some error occured!"
    elif cmd_type == "login":
        print("logging in...")
        rsd = userSt.login(*cmd_args)
        if rsd: