From 779b1e6077e909f64e5ff2569876f29f4d33da46 Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Wed, 27 Nov 2019 09:26:41 -0800 Subject: [PATCH] add doc about using ws to run a cobra server/publisher/subscriber --- docker-compose.yml | 8 +++++ docs/cobra.md | 81 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 docs/cobra.md diff --git a/docker-compose.yml b/docker-compose.yml index 66d14b9a..1d13beea 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -55,5 +55,13 @@ services: # networks: # - ws-net +# compile: +# image: alpine +# entrypoint: sh +# stdin_open: true +# tty: true +# volumes: +# - /Users/bsergeant/src/foss:/home/bsergean/src/foss + networks: ws-net: diff --git a/docs/cobra.md b/docs/cobra.md new file mode 100644 index 00000000..798b4bb1 --- /dev/null +++ b/docs/cobra.md @@ -0,0 +1,81 @@ +## General + +cobra is a real time messaging server. The `ws` utility can run a cobra server (named snake), and has client to publish and subscribe to a cobra server. + +Bring up 3 terminals and run a server, a publisher and a subscriber in each one. As you publish data you should see it being received by the subscriber. You can run `redis-cli MONITOR` too to see how redis is being used. + +### Server + +You will need to have a redis server running locally. To run the server: + +``` +$ cd /ixsnake/ixsnake +$ ws snake +{ + "apps": { + "FC2F10139A2BAc53BB72D9db967b024f": { + "roles": { + "_sub": { + "secret": "66B1dA3ED5fA074EB5AE84Dd8CE3b5ba" + }, + "_pub": { + "secret": "1c04DB8fFe76A4EeFE3E318C72d771db" + } + } + } + } +} + +redis host: 127.0.0.1 +redis password: +redis port: 6379 +``` + +### Publisher + +``` +$ cd /ws +$ ws cobra_publish --appkey FC2F10139A2BAc53BB72D9db967b024f --endpoint ws://127.0.0.1:8008 --rolename _pub --rolesecret 1c04DB8fFe76A4EeFE3E318C72d771db test_channel cobraMetricsSample.json +[2019-11-27 09:06:12.980] [info] Publisher connected +[2019-11-27 09:06:12.980] [info] Connection: Upgrade +[2019-11-27 09:06:12.980] [info] Sec-WebSocket-Accept: zTtQKMKbvwjdivURplYXwCVUCWM= +[2019-11-27 09:06:12.980] [info] Sec-WebSocket-Extensions: permessage-deflate; server_max_window_bits=15; client_max_window_bits=15 +[2019-11-27 09:06:12.980] [info] Server: ixwebsocket/7.4.0 macos ssl/DarwinSSL zlib 1.2.11 +[2019-11-27 09:06:12.980] [info] Upgrade: websocket +[2019-11-27 09:06:12.982] [info] Publisher authenticated +[2019-11-27 09:06:12.982] [info] Published msg 3 +[2019-11-27 09:06:12.982] [info] Published message id 3 acked +``` + +### Subscriber + +``` +$ ws cobra_subscribe --appkey FC2F10139A2BAc53BB72D9db967b024f --endpoint ws://127.0.0.1:8008 --rolename _pub --rolesecret 1c04DB8fFe76A4EeFE3E318C72d771db test_channel +#messages 0 msg/s 0 +[2019-11-27 09:07:39.341] [info] Subscriber connected +[2019-11-27 09:07:39.341] [info] Connection: Upgrade +[2019-11-27 09:07:39.341] [info] Sec-WebSocket-Accept: 9vkQWofz49qMCUlTSptCCwHWm+Q= +[2019-11-27 09:07:39.341] [info] Sec-WebSocket-Extensions: permessage-deflate; server_max_window_bits=15; client_max_window_bits=15 +[2019-11-27 09:07:39.341] [info] Server: ixwebsocket/7.4.0 macos ssl/DarwinSSL zlib 1.2.11 +[2019-11-27 09:07:39.341] [info] Upgrade: websocket +[2019-11-27 09:07:39.342] [info] Subscriber authenticated +[2019-11-27 09:07:39.345] [info] Subscriber: subscribed to channel test_channel +#messages 0 msg/s 0 +#messages 0 msg/s 0 +#messages 0 msg/s 0 +{"baz":123,"foo":"bar"} + +#messages 1 msg/s 1 +#messages 1 msg/s 0 +#messages 1 msg/s 0 +{"baz":123,"foo":"bar"} + +{"baz":123,"foo":"bar"} + +#messages 3 msg/s 2 +#messages 3 msg/s 0 +{"baz":123,"foo":"bar"} + +#messages 4 msg/s 1 +^C +```