forked from hkg36/websockframework
/
EventNotifyServer.py
47 lines (43 loc) · 1.48 KB
/
EventNotifyServer.py
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
37
38
39
40
41
42
43
44
45
46
47
#coding:utf-8
from tools.helper import LoadEvent
__author__ = 'amen'
import QueueWork
import getopt
import importlib
import sys
from datamodel.connection_info import ConnectionInfo
import dbconfig
import json
def RequestWork(params,body,reply_queue):
event=json.loads(body)
toid=event['touid']
eo=LoadEvent(event)
if eo is None:
return
with dbconfig.Session() as session:
conn=session.query(ConnectionInfo).filter(ConnectionInfo.uid==toid).first()
to_push=json.dumps({"push":True,
"type":"event",
"data":{
"event":eo
}
})
QueueWork.producer.publish(body=to_push,delivery_mode=2,headers={"connid":conn.connection_id},
routing_key=conn.queue_id,
compression='gzip')
if __name__ == '__main__':
config_model='configs.frontend'
opts, args=getopt.getopt(sys.argv[1:],'c:',
['config='])
for k,v in opts:
if k in ('-c','--config'):
config_model=v
try:
configs=importlib.import_module(config_model)
except Exception,e:
print str(e)
exit(0)
QueueWork.WorkFunction=RequestWork
QueueWork.init(configs.Queue_Server,configs.Queue_Port,configs.Queue_Path,
configs.Queue_User,configs.Queue_PassWord,'sys.event')
QueueWork.run()