This repository has been archived by the owner. It is now read-only.
websockets for reddit
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
puppet
reddit_service_websockets
tests
.gitignore
Dockerfile Add service quiescing and connection shedding. Feb 27, 2017
Dockerfile.test
LICENSE Add license and readme Apr 8, 2016
README.md
Vagrantfile Add Vagrant dev environment setup from cookiecutter May 28, 2017
example.ini Connect to correct rabbitmq hostname. Mar 5, 2018
example_secrets.json
setup.py

README.md

reddit-service-websockets

Websockets for reddit.

This service is primarily aimed at broadcasting messages to clients. It can also optionally report to the backend when clients connect or disconnect. All communication with other backend services is mediated by an AMQP broker (RabbitMQ).

Usage

Applications using this service are in charge of managing authorization. The service validates that incoming requests were authorized by the main application using a message authentication code. The path portion of a websocket request indicates which message "namespace" the socket will receive.

Messages are sent to the service via an AMQP fan out exchange. Each worker process binds to the exchange and will receive all messages sent to it. Messages are dispatched to appropriate websocket clients by mapping the message's routing key to the socket namespace specified in the websocket request.

If configured to do so, the service will also insert connect/disconnect messages onto a topic exchange in AMQP.

Testing and Development

There are two Docker images provided for development and testing.

  • Dockerfile: A Docker image definition for running a local version of the service.
  • Dockerfile.test: A Docker image definition for running tests.
# Exposes websocket service at 127.0.0.1:9090
docker build . -t ws-server -f Dockerfile  && docker run --rm -p 9090:9090 ws-server

# Run code tests
docker build . -t ws-tests -f Dockerfile.test  && docker run ws-tests

Further reading

This service is used and written for reddit.com's socket needs. Client and server code examples can be found in the monolith's repos: