All Projects β†’ voxpelli β†’ Node Pg Pubsub

voxpelli / Node Pg Pubsub

Licence: mit
A Publish/Subscribe implementation on top of PostgreSQL NOTIFY/LISTEN

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
Asyncorm
Fully Async ORM inspired in django's
Stars: ✭ 182 (-6.19%)
Mutual labels:  postgres
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
Synth
The Declarative Data Generator
Stars: ✭ 161 (-17.01%)
Mutual labels:  postgres
Frappe
Low code web framework for real world applications, in Python and Javascript
Stars: ✭ 3,349 (+1626.29%)
Mutual labels:  postgres
Condenser
Condenser is a database subsetting tool
Stars: ✭ 189 (-2.58%)
Mutual labels:  postgres
Imgsmlr
Similar images search for PostgreSQL
Stars: ✭ 181 (-6.7%)
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

Linting Build Status Node CI Build Status Coverage Status dependencies Status Known Vulnerabilities js-semistandard-style

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 from EventEmitter one can also add it oneself. Returns a Promise 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 a Promise 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
  • 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].