Project

General

Profile

Statistics
| Branch: | Revision:

gdp-if / websocket-subscriber / README.md @ master

History | View | Annotate | Download (3.44 KB)

1 e1535212 Nitesh Mor
# GDP Websocket gateway
2
3
A gateway for subscribing to a GDP log via websockets. 
4
5
# Requirements and setup
6
7
Requires following to be installed:
8
9
- GDP C library (libgdp)
10
- GDP python bindings
11
- Python 2.7
12
- twisted, Event-based framework for internet applications (package
13
  `python-twisted` on Ubuntu)
14
- autobahn, WebSocket/WAMP implementation for Python/Twisted (package
15
  `python-autobahn` on Ubuntu)
16
17
Once the required dependencies are met, running a gateway is as simple as
18
19
    python gdp-ws.py --port XXXX
20
21 d84f411f Nitesh Mor
This opens a websocket server on the specified port. If needed, a secure
22
websocket interface can also be instantiated. See `python gdp-ws.py -h` for
23
invocation details. Note that setting up secure websockets requires you to have
24
appropriate certificate/private keys.
25 e1535212 Nitesh Mor
26
# Client interaction
27
28
Clients issue subscription requests by sending a JSON encoded *text* message,
29
which should at least specify the `logname` (and optionally the range of records
30
as well). An example client=>server message looks like the following:
31
32
    {"logname": "a-human-readable-logname", "startrec": 0, "numrec": 20}
33
34
The `startrec` and `numrec` represent the range of records and are optional
35
parameters. The behavior is the same as for `gdp_gcl_subscribe` API call in the
36
C library. The default values are `startrec = 0` and `numrec = 1`, which implies
37
a request for *only* the next available record. For the subscription to run
38
forever, use `numrec = 0` (see documentation `doc/gdp-programmatic-api.html`)
39
40
The websocket gateway subscribes to the specified log on behalf of the client
41
and sends the events it receives from a log-server to the client. An example
42
response looks as follows:
43
44
```
45
{"logname": "a-human-readable-logname", "ep_stat": [200, "OK [200 = 0xc8]"],
46 d91f226e Nitesh Mor
"datum": {"recno": 24, "data": "hello", "ts": {"tv_sec": 1498143987,
47 4e0b39be Nitesh Mor
"tv_accuracy": 0.0, "tv_nsec": 662371000}}, "type": 1}
48 e1535212 Nitesh Mor
```
49
50
A quick summary of the various fields is:
51
52
* `logname`: the name of the log, of course. Useful in case a client has
53
             multiple subscriptions active
54
* `ep_stat`: a status code returned by the C library (EP_STAT)
55
* `type`   : the type of event. Valid types are defined by the C-library, see 
56
             `gdp/gdp.h`.
57 4e0b39be Nitesh Mor
* `datum`  : the datum returned as a result of subscription. Only valid if the
58
             event type is `GDP_EVENT_DATA` (1).
59 e1535212 Nitesh Mor
60
A client can send multiple subscription requests over the same websocket. Each
61
such request is treated as an independent request, thus a client will receive
62
multiple copies of any new data if it has duplicate active subscriptions on the
63
same log. However, such subscriptions are lost in case the websocket connection
64
goes away; it is the responsibility of a client to re-send the subscription
65
request if the connection fails for any reason.
66
67 39226b10 Nitesh Mor
Note that any exceptions encountered by the gateway are sent back to the client
68
as unformatted text (see Limitations). Thus, a client should be ready to handle
69
the incoming data that is not a well formatted JSON.
70
71 e1535212 Nitesh Mor
# Limitations
72
73 39226b10 Nitesh Mor
* Only textual mode is supported for the moment. Binary data (in the logs,
74 eb23c2ea Nitesh Mor
  logname, etc) does not work.
75
* In particular, using JSON as the transport format rules out supporting
76
  records with binary payload.
77 39226b10 Nitesh Mor
* Any exceptions that the gateway encountered while processing a request are
78
  sent back to the client as it is. In some cases, it makes sense (such as a
79
  non-existent logname causing `Error 600`), but in many cases it does not (the
80
  gateway server losing connection to the GDP infrastucture)