Skip to content

DbListenerPg

do- edited this page Mar 3, 2024 · 17 revisions

DbListenerPg is a doix Router that LISTENs to a PostrgreSQL notification channel and forwards the incoming strings to registered processors: normally, DbChannelPg instances.

Constructor

const {DbListenerPg} = require ('doix-db-postgresql')

const dbl = new DbListenerPg ({
    db: {host: '127.0.0.1', port: 5432},
})

dbl.add (new DbChannelPg (app1, {
  name: 'hotline',
  on: {
    start: function () {
//    this.rq = {type: 'mail', action: 'send', id: this.notification.payload)
//    this.rq = JSON.parse (this.notification.payload) // Generic example, be careful
    },
  },
}))

// dbl.add (new DbChannelPg (app2, {...}) 

await dbl.listen ()

The only parameter here is the bag of options.

Options

Name Description
db options forwarded to the native constructor

Events

Name Description
start emitted at the end of the listen () method
finish emitted at the end of the close () method

Methods

listen ()

Starts listening to incoming requests. For each of them, feeds the string received to the first matching processor, following the basic Router logic.

close ()

This asynchronous method makes the router stop listening to incoming requests.

Clone this wiki locally