-
Notifications
You must be signed in to change notification settings - Fork 2
DbListenerPg
do- edited this page Aug 19, 2024
·
17 revisions
DbListenerPg
is a Router that LISTENs to a PostrgreSQL notification channel and forwards the incoming strings to registered processors: normally,
instances.
const {DbListenerPg, DbQueuesRouterPg} = require ('doix-db-postgresql')
const dbl = new DbListenerPg ({
channel: 'hotline',
db: {host: '127.0.0.1', port: 5432},
logger
})
dbl.add (new DbServicePg (app1, {
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 DbQueuesRouterPg (app2, {...})
await dbl.listen ()
The only parameter here is the bag of options.
Name | Description |
---|---|
channel |
The channel name to LISTEN on |
db |
options forwarded to the native constructor |
Name | Description |
---|---|
pool |
The DbPoolPg instance created according to db settings |
Name | Description |
---|---|
start |
emitted at the end of the listen () method |
notification |
emitted for each notification, with a DbNotificationPg instance as payload |
finish |
emitted at the end of the close () method |
Starts listening to incoming notifications. For each of them, creates a DbNotificationPg instance and feeds it to the first matching processor, following the basic Router logic.
This asynchronous method makes the router stop listening to incoming requests.