Skip to content
This repository has been archived by the owner on Feb 25, 2023. It is now read-only.

suhlig/pg-sse

Repository files navigation

pg-sse - Relays Database Updates to an SSE stream

Build Status

Listens to a Postgres channel and distributes any messages to HTTP clients via server-sent events (SSE).

The channel could be filled e.g. from a database trigger, as demonstrated in Brent Tubbs' Postgres + React TodoMVC Example. A new DB record would then trigger a notification to be sent to the channel, which is picked up by the pg_listen.rb process, which posts it via HTTP to sse_server.rb, which broadcasts it via SSE to all connected clients.

This is partially based on code in this gist.

Getting Started

$ bundle install
$ PORT=4567 DB_URL=postgres:///mydb SSE_URL=http://localhost:4567 foreman start
$ open http://localhost:4567/

Just listen in with curl:

$ curl -s -H "Accept: text/event-stream" http://localhost:4567/stream

Deployment

Just like the front end, I deploy this one to Bluemix with a simple cf push. Have a look at the manifest.yml for details. Heroku should be similar.

Domains

cf create-domain <org> <domain>.eu-gb.mybluemix.net

To keep things simple, it is best to choose the same domain as where the main web app was deployed to.

Configuration

The URL to the SSE stream is required by both the listener and the front end. The SSE_URL is set accordingly for both. Look at the manifest.yml of the listener and the front end.

Contributing

Please see CONTRIBUTING.md.

License

pg-sse is Copyright© 2016 Steffen Uhlig. It is free software, and may be redistributed under the terms specified in the LICENSE file.

About

Relay Database Updates to an HTTP SSE stream

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •