This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

@forrestjs/service-postgres-pubsub

4.7.2 • Public • Published

@forrestjs/service-postgres-pubsub

🚧 DEPRECATED 🚧 service-pg-pubsub will come soon!

This service leverages a Postgres database to implement a pub/sub mechanism that can scale across multiple instances of a web service.

It implements node-pg-pubsub that is a library that works just fine.

Usage

import { addChannel, publish, once } from '@forrestjs/service-postgres-pubsub'

// create a persistent channel, the return value is a function that
// you can call to cleanup the subscription
const removeChannel = addChannel('channelName', msh => {
    console.log('channel was called with', msh)
});

// you do not need to cleanup this, it's going to be fired just once
once('channelName', () => { ... })

publish('channelName', { some: 'data' })
// -> expect the console log here

All the methods above take a 3rd argument called connectionName that allows to target a specific Postgres instance in case your app is connected to multiple ones.

Configuration

You can provide multiple Postgres connections, they should be identified by a connectionName property. If omitted it's going to be default.

registerAction({
  hook: SETTINGS,
  name: '♦ boot',
  handler: async ({ settings }) => {
    settings.postgresPubsub = [
      {
        connectionName: 'default',
        host: config.get('PG_HOST'),
        port: config.get('PG_PORT'),
        database: config.get('PG_DATABASE'),
        username: config.get('PG_USERNAME'),
        password: config.get('PG_PASSWORD'),
      },
    ];
  },
});

Package Sidebar

Install

npm i @forrestjs/service-postgres-pubsub

Weekly Downloads

5

Version

4.7.2

License

MIT

Unpacked Size

9.84 kB

Total Files

8

Last publish

Collaborators

  • marcopeg