This project is essentially a Redis-to-WebSocket adapter in the sense that it will publish to WebSocket clients, whatever string you publish to Redis.
If you connect to redis via redis-cli and type publish trades "some json here", this project will send over WebSocket to all connected clients the message "some json here".
This means we could reuse this project for trades, ticker and orderbook without any code change, only a few runtime environment variables changed such as what topic we subscribe to in Redis.
git clone --recursive [email protected]:bitwyre/megaphone.gitmake deps -C megaphone (requires autotools, autoconf, automake for building libuv)make -C megaphoneNow you should have an executable, megaphone, without any non-standard dependencies to worry about (you can move this executable across different Linux systems without breakage).
Megaphone is a stand-alone executable you launch with a few environment variables:
REDIS_HOST is the address/hostname to the main, internal, Redis pub/sub nodeREDIS_PORT is the port to said Redis nodeREDIS_TOPIC is the topic we subscribe to, and listen to events on. What you publish to Redis on this topic will be sent to all WebSocket clients connected to this Megaphone instanceSERVICE_IP is the hostname of the WebSocket serverSERVICE_PORT is the port of the WebSocket serverSERVICE_PATH is the path of the WebSocket serverExample:
You need a redis-server running, for instance on localhost and port 6379.
REDIS_HOST=localhost REDIS_PORT=6379 REDIS_TOPIC=trades ./megaphone launches one instance, you may launch as many you want, distributing the load among megaphone instances.
Now you may test by starting redis-cli and typing publish trades "hello world!", which should trigger a distribution of "hello world! over all to megaphone connected WebSocket clients.
docker run --rm \
-e "REDIS_TOPIC=pubsub_topic" \
-e "REDIS_PORT=6379" \
-e "REDIS_HOST=127.0.0.1" \
-e "SERVICE_IP=127.0.0.1" \
-e "SERVICE_PORT=4545" \
-e "SERVICE_PATH=/ws/topic" \
--net=host \
bitwyre/megaphone:latest
Content type
Image
Digest
Size
27.6 MB
Last updated
about 5 years ago
docker pull bitwyre/megaphone