-
Notifications
You must be signed in to change notification settings - Fork 2
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.
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.
Name | Description |
---|---|
db |
options forwarded to the native constructor |
Name | Description |
---|---|
start |
emitted at the end of the listen () method |
finish |
emitted at the end of the close () method |
Starts listening to incoming requests. For each of them, feeds the string received to the first matching processor, following the basic Router logic.
This asynchronous method makes the router stop listening to incoming requests.