ws Pub/Sub

110 views
Skip to first unread message

hoffmanroni

unread,
Jul 22, 2019, 4:12:05 PM7/22/19
to AquaQ kdb+/TorQ
Hello,

I am trying to just test pub sub over websockets.  I established a connection by setting .z.ws to 

.z.ws:{neg[.z.w] -8!.j.j[.html.evaluate[.j.k -9!x]];}


but I can't seem to get pub/sub working.  Wondering if someone can help?

I have upd something like this

upd:{[tab;data]
    if[not tab in (`heartbeat`logmsg);
        //pub to subscribers
        .u.pub[tab;data];
        .html.pub[tab;data]
    ]
    }

and then trying to subscribe in ws client to table `test by 

.html.wssub[`test]

but can't seem to get it working, did I miss something?
I've also done

.html.init[`test]

Thanks!

Kevin O'Hare

unread,
Aug 2, 2019, 11:03:13 AM8/2/19
to AquaQ kdb+/TorQ
Dear Roni Hoffman,Currently the definition of .z.ws we are using relies on the .j.j/.j.k functions. However these functions are not able to handle symbol values. This means that it is not possible to call the .html.wssub directly as it is dependant on a symbol argument.One way to solve this would be to define a wrapper function for wssub which casts the argument to a symbol. .i.e
.html.wssub1:{.html.wssub `$x}
and please ensure the html subscription has been initialised
.html.init[`test]
We can then call .html.wssub1 from Javascript by using the following code. This requires the c.js package available from github
//Change the username password host and port
websocket = new WebSocket("ws://username:pass...@127.0.0.1:6000");

msg = {func:".html.wssub1",arg1:"test"};
websocket.send(serialize(JSON.stringify(msg)));
Note you will also need to modify the websocket.onmessage to handle the responses. .i.e
websocket.onmessage = function(e){
   data = JSON.parse(deserialize(e.data));
   ...
}
You can verify that this has been successful by checking the subscription dictionary on the kdb side using .html.w .I hope this helps resolve your issue.Regards, Kevin O'Hare

hoffmanroni

unread,
Aug 2, 2019, 4:28:09 PM8/2/19
to AquaQ kdb+/TorQ
Kevin, thanks so much for this, I will try.
Reply all
Reply to author
Forward
0 new messages