voxpelli / Node Pg Pubsub
Licence: mit
A Publish/Subscribe implementation on top of PostgreSQL NOTIFY/LISTEN
Stars: β 194
Programming Languages
javascript
184084 projects - #8 most used programming language
Projects that are alternatives of or similar to Node Pg Pubsub
Postgres Migrations
π¦ A Stack Overflow-inspired PostgreSQL migration library with strict ordering and immutable migrations
Stars: β 161 (-17.01%)
Mutual labels: postgres, node-js
pg-ipc
IPC over PostgreSQL LISTEN/NOTIFY/UNLISTEN exposed as an EventEmitter
Stars: β 27 (-86.08%)
Mutual labels: postgres, pubsub
pg-pubsub
Reliable PostgreSQL LISTEN/NOTIFY with inter-process lock support
Stars: β 50 (-74.23%)
Mutual labels: postgres, pubsub
Node Connect Pg Simple
A simple, minimal PostgreSQL session store for Connect/Express
Stars: β 166 (-14.43%)
Mutual labels: postgres, node-js
Democracy.js
Node.js unicast discovery, leader-citizen elections and pub/sub.
Stars: β 175 (-9.79%)
Mutual labels: pubsub
Liftbridge
Lightweight, fault-tolerant message streams.
Stars: β 2,175 (+1021.13%)
Mutual labels: pubsub
Frappe
Low code web framework for real world applications, in Python and Javascript
Stars: β 3,349 (+1626.29%)
Mutual labels: postgres
Postgresqltuner
Simple script to analyse your PostgreSQL database configuration, and give tuning advice
Stars: β 2,214 (+1041.24%)
Mutual labels: postgres
Bus
πMinimalist message bus implementation for internal communication
Stars: β 187 (-3.61%)
Mutual labels: pubsub
Space Cloud
Open source Firebase + Heroku to develop, scale and secure serverless apps on Kubernetes
Stars: β 3,323 (+1612.89%)
Mutual labels: postgres
Titra
titra - modern open source project time tracking for freelancers and small teams
Stars: β 189 (-2.58%)
Mutual labels: node-js
Plugin Nvm
Node version manager wrapper for Fish shell
Stars: β 173 (-10.82%)
Mutual labels: node-js
Fullstack Boilerplate
Fullstack boilerplate using Typescript, React, GraphQL
Stars: β 181 (-6.7%)
Mutual labels: postgres
Focus Budget Manager
Budget Manager application built with Vue.js, Node.js, Express.js and MongoDB
Stars: β 189 (-2.58%)
Mutual labels: node-js
Databases
Async database support for Python. π
Stars: β 2,602 (+1241.24%)
Mutual labels: postgres
Jspp
JS++, a sound static/dynamic programming language for web development
Stars: β 177 (-8.76%)
Mutual labels: node-js
PG PubSub
A Publish/Subscribe implementation on top of PostgreSQL NOTIFY/LISTEN
Installation
npm install pg-pubsub --save
Requirements
Node.js >= 12.x Postgres >= 9.4
Usage
const PGPubsub = require('pg-pubsub');
const pubsubInstance = new PGPubsub(uri[, options]);
Options
{
[log]: Function // default: silent when NODE_ENV=production, otherwise defaults to console.log(...)
}
Methods
-
addChannel(channelName[, eventListener]) β starts listening on a channel and optionally adds an event listener for that event. As
PGPubsub
inherits fromEventEmitter
one can also add it oneself. Returns aPromise
that resolves when the listening has started. - removeChannel(channelName[, eventListener]) β either removes all event listeners and stops listeneing on the channel or removes the specified event listener and stops listening on the channel if that was the last listener attached.
-
publish(channelName, data) β publishes the specified data JSON-encoded to the specified channel. It may be better to do this by sending the
NOTIFY channelName, '{"hello":"world"}'
query yourself using your ordinary Postgres pool, rather than relying on the single connection of this module. Returns aPromise
that will become rejected or resolved depending on the success of the Postgres call. - close(): Promise β closes down the database connection and removes all listeners. Useful for graceful shutdowns.
- All EventEmitter methods are inherited from
EventEmitter
Examples
Simple
const pubsubInstance = new PGPubsub('postgres://[email protected]/database');
await pubsubInstance.addChannel('channelName', function (channelPayload) {
// Process the payload β if it was JSON that JSON has been parsed into an object for you
});
await pubsubInstance.publish('channelName', { hello: "world" });
The above sends NOTIFY channelName, '{"hello":"world"}'
to PostgreSQL, which will trigger the above listener with the parsed JSON in channelPayload
.
Advanced
const pubsubInstance = new PGPubsub('postgres://[email protected]/database');
await pubsubInstance.addChannel('channelName');
// pubsubInstance is a full EventEmitter object that sends events on channel names
pubsubInstance.once('channelName', channelPayload => {
// Process the payload
});
Description
Creating a PGPubsub
instance will not do much up front. It will prepare itself to start a Postgres connection once the first channel is added and then it will keep a connection open until its shut down, reconnecting it if it gets lost, so that it can constantly listen for new notifications.
Lint / Test
- setup a postgres database to run the integration tests
- the easist way to do this is via docker,
docker run -it -p 5432:5432 -e POSTGRES_DB=pgpubsub_test postgres
- the easist way to do this is via docker,
npm test
For an all-in-one command, try:
# fire up a new DB container, run tests against it, and clean it up!
docker rm -f pgpubsub_test || true && \
docker run -itd -p 5432:5432 -e POSTGRES_DB=pgpubsub_test --name pgpubsub_test postgres && \
npm test && \
docker rm -f pgpubsub_test
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].