summaryrefslogtreecommitdiff
path: root/datastore/server.py
blob: 8b9ca4ee1b4871154b2328e3235582cf3b51c629 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from sys import exit
from stompclient import PublishSubscribeClient
from threading import Thread
from store.controller import MQStoreController
from time import sleep

import config

client = PublishSubscribeClient(config.STOMP_HOST, config.STOMP_PORT)
listener = Thread(target=client.listen_forever, name='Frame-Receiver')
listener.start()
client.listening_event.wait()
r = client.connect(config.STOMP_LOGIN, config.STOMP_PASSCODE)
if r.command != "CONNECTED":
    print "Failed to connect to {0}:{1}".format(config.STOMP_HOST,config.STOMP_PORT)
    print r
    exit(1)


controller = MQStoreController(client, config.CHANNELS, config.PROCESSORS)
client.subscribe(config.STOMP_QUEUE_PUT, controller.cb_put)
client.subscribe(config.STOMP_QUEUE_GET, controller.cb_get)
client.subscribe(config.STOMP_QUEUE_SUBSCRIBE, controller.cb_subscribe)

while True:
    try:
        sleep(1)
    except KeyboardInterrupt:
        print "shutdown"
        try:
            client.shutdown_event.set()
        except:
            pass
        exit(0)