source: trunk/zoo-project/zoo-services/utils/open-api/server/subscriber.py @ 963

Last change on this file since 963 was 962, checked in by djay, 4 years ago

Update OGC API - Processes documentation and implementation, providing a browsable User Interface to Processes.

  • Property svn:executable set to *
File size: 1.5 KB
Line 
1#!/usr/bin/python3
2# cf. https://github.com/joewalnes/websocketd/wiki/Simple-Python-Duplex-Example
3#
4# example usage:
5# websocketd --port=4430 --ssl --sslcert /ssl/fullchain.pem --sslkey /ssl/privkey.pem subscriber.py --devconsole
6#
7
8from sys import stdout, stdin
9import sys
10import threading
11import redis
12import json
13
14mThreads=[]
15r = redis.Redis(host='localhost', port=6379, db=0)
16
17def send(t):
18    # send string to web page
19    stdout.write(t+'\n')
20    stdout.flush()
21
22def listenMessages(jobID=None):
23    global r
24    p = r.pubsub()
25    p.subscribe(jobID)
26    hasSend=False
27    for raw_message in p.listen():
28        try:
29            send(str(raw_message["data"],'utf-8'))
30            hasSend=True
31            try:
32                tmp=json.loads(str(raw_message["data"],'utf-8'))
33                if tmp is not None and "outputs" in tmp:
34                    sys.exit()
35            except Exception as e:
36                print(str(e))
37                return
38        except:
39            if not(hasSend):
40                send(str(raw_message["data"]))
41
42
43def receive():
44    global n
45    global mThreads
46    while True:
47        t = stdin.readline().strip()
48        if not t:
49            break
50        t1 = t.split(" ")
51        if t1[0]=="SUB":
52            mThreads += [threading.Thread(target=listenMessages,kwargs={"jobID":t1[1]})]
53            mThreads[len(mThreads)-1].start()
54        else:
55            send(t)
56
57t0 = threading.Thread(target=receive)
58t0.start()
59
60t0.join()
61for i in range(len(mThreads)):
62    mThreads[i].join()
Note: See TracBrowser for help on using the repository browser.

Search

Context Navigation

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png